mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-10 15:46:42 +02:00
Clean up asio includes
This commit is contained in:
parent
4f29f000de
commit
caef2b7b87
25 changed files with 120 additions and 74 deletions
|
@ -25,6 +25,11 @@
|
|||
#include "common/str_compat.hpp"
|
||||
#include "message/hello.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio/read.hpp>
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
#include <boost/asio/write.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
|
@ -34,6 +39,59 @@ using namespace std;
|
|||
|
||||
static constexpr auto LOG_TAG = "Connection";
|
||||
|
||||
PendingRequest::PendingRequest(const boost::asio::strand<boost::asio::any_io_executor>& strand, uint16_t reqId, const MessageHandler<msg::BaseMessage>& handler)
|
||||
: id_(reqId), timer_(strand), strand_(strand), handler_(handler)
|
||||
{
|
||||
}
|
||||
|
||||
PendingRequest::~PendingRequest()
|
||||
{
|
||||
handler_ = nullptr;
|
||||
timer_.cancel();
|
||||
}
|
||||
|
||||
void PendingRequest::setValue(std::unique_ptr<msg::BaseMessage> value)
|
||||
{
|
||||
boost::asio::post(strand_, [this, self = shared_from_this(), val = std::move(value)]() mutable {
|
||||
timer_.cancel();
|
||||
if (handler_)
|
||||
handler_({}, std::move(val));
|
||||
});
|
||||
}
|
||||
|
||||
uint16_t PendingRequest::id() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
void PendingRequest::startTimer(const chronos::usec& timeout)
|
||||
{
|
||||
timer_.expires_after(timeout);
|
||||
timer_.async_wait([this, self = shared_from_this()](boost::system::error_code ec) {
|
||||
if (!handler_)
|
||||
return;
|
||||
if (!ec)
|
||||
{
|
||||
// !ec => expired => timeout
|
||||
handler_(boost::asio::error::timed_out, nullptr);
|
||||
handler_ = nullptr;
|
||||
}
|
||||
else if (ec != boost::asio::error::operation_aborted)
|
||||
{
|
||||
// ec != aborted => not cancelled (in setValue)
|
||||
// => should not happen, but who knows => pass the error to the handler
|
||||
handler_(ec, nullptr);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bool PendingRequest::operator<(const PendingRequest& other) const
|
||||
{
|
||||
return (id_ < other.id());
|
||||
}
|
||||
|
||||
|
||||
|
||||
ClientConnection::ClientConnection(boost::asio::io_context& io_context, const ClientSettings::Server& server)
|
||||
: io_context_(io_context), strand_(boost::asio::make_strand(io_context_.get_executor())), resolver_(strand_), socket_(strand_), reqId_(1), server_(server)
|
||||
{
|
||||
|
|
|
@ -26,7 +26,10 @@
|
|||
#include "message/message.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/any_io_executor.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
#include <boost/asio/strand.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <atomic>
|
||||
|
@ -51,61 +54,22 @@ using MessageHandler = std::function<void(const boost::system::error_code&, std:
|
|||
class PendingRequest : public std::enable_shared_from_this<PendingRequest>
|
||||
{
|
||||
public:
|
||||
PendingRequest(const boost::asio::strand<boost::asio::any_io_executor>& strand, uint16_t reqId, const MessageHandler<msg::BaseMessage>& handler)
|
||||
: id_(reqId), timer_(strand), strand_(strand), handler_(handler){};
|
||||
|
||||
virtual ~PendingRequest()
|
||||
{
|
||||
handler_ = nullptr;
|
||||
timer_.cancel();
|
||||
}
|
||||
PendingRequest(const boost::asio::strand<boost::asio::any_io_executor>& strand, uint16_t reqId, const MessageHandler<msg::BaseMessage>& handler);
|
||||
virtual ~PendingRequest();
|
||||
|
||||
/// Set the response for the pending request and passes it to the handler
|
||||
/// @param value the response message
|
||||
void setValue(std::unique_ptr<msg::BaseMessage> value)
|
||||
{
|
||||
boost::asio::post(strand_, [this, self = shared_from_this(), val = std::move(value)]() mutable {
|
||||
timer_.cancel();
|
||||
if (handler_)
|
||||
handler_({}, std::move(val));
|
||||
});
|
||||
}
|
||||
void setValue(std::unique_ptr<msg::BaseMessage> value);
|
||||
|
||||
/// @return the id of the request
|
||||
uint16_t id() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
uint16_t id() const;
|
||||
|
||||
/// Start the timer for the request
|
||||
/// @param timeout the timeout to wait for the reception of the response
|
||||
void startTimer(const chronos::usec& timeout)
|
||||
{
|
||||
timer_.expires_after(timeout);
|
||||
timer_.async_wait([this, self = shared_from_this()](boost::system::error_code ec) {
|
||||
if (!handler_)
|
||||
return;
|
||||
if (!ec)
|
||||
{
|
||||
// !ec => expired => timeout
|
||||
handler_(boost::asio::error::timed_out, nullptr);
|
||||
handler_ = nullptr;
|
||||
}
|
||||
else if (ec != boost::asio::error::operation_aborted)
|
||||
{
|
||||
// ec != aborted => not cancelled (in setValue)
|
||||
// => should not happen, but who knows => pass the error to the handler
|
||||
handler_(ec, nullptr);
|
||||
}
|
||||
});
|
||||
}
|
||||
void startTimer(const chronos::usec& timeout);
|
||||
|
||||
/// Needed to put the requests in a container
|
||||
bool operator<(const PendingRequest& other) const
|
||||
{
|
||||
return (id_ < other.id());
|
||||
}
|
||||
|
||||
bool operator<(const PendingRequest& other) const;
|
||||
|
||||
private:
|
||||
uint16_t id_;
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
// 3rd party headers
|
||||
#include <alsa/asoundlib.h>
|
||||
#include <boost/asio/posix/stream_descriptor.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <chrono>
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "player.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <cstdio>
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include "stream.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <atomic>
|
||||
|
|
|
@ -29,7 +29,8 @@
|
|||
#include "server_settings.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <memory>
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "server_settings.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <atomic>
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
// prototype/interface header file
|
||||
#include "control_session_tcp.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio/read_until.hpp>
|
||||
#include <boost/asio/write.hpp>
|
||||
|
||||
// local headers
|
||||
#include "common/aixlog.hpp"
|
||||
#include "message/pcm_chunk.hpp"
|
||||
|
|
|
@ -23,7 +23,10 @@
|
|||
#include "control_session.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/any_io_executor.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/strand.hpp>
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <deque>
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
// local headers
|
||||
// prototype/interface header file
|
||||
#include "control_session_ws.hpp"
|
||||
|
||||
// local headers
|
||||
#include "common/aixlog.hpp"
|
||||
#include "message/pcm_chunk.hpp"
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "control_session.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio/strand.hpp>
|
||||
#include <boost/beast/core.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <avahi-common/malloc.h>
|
||||
#include <avahi-common/simple-watch.h>
|
||||
#include <avahi-common/timeval.h>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <atomic>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#define PUBLISH_MDNS_HPP
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <string>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/***
|
||||
This file is part of snapcast
|
||||
Copyright (C) 2014-2021 Johannes Pohl
|
||||
Copyright (C) 2014-2022 Johannes Pohl
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -33,7 +33,8 @@
|
|||
#include "streamreader/stream_manager.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <memory>
|
||||
|
|
|
@ -32,7 +32,8 @@
|
|||
#include "streamreader/stream_manager.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <memory>
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
#include "streamreader/stream_manager.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/any_io_executor.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/strand.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <atomic>
|
||||
|
@ -39,8 +41,6 @@
|
|||
#include <vector>
|
||||
|
||||
|
||||
namespace net = boost::asio;
|
||||
|
||||
|
||||
class StreamSession;
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "stream_session.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
// standard headers
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/***
|
||||
This file is part of snapcast
|
||||
Copyright (C) 2014-2021 Johannes Pohl
|
||||
Copyright (C) 2014-2022 Johannes Pohl
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -25,9 +25,8 @@
|
|||
#include <deque>
|
||||
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
// namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
|
||||
|
||||
/// Endpoint for a connected control client.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/***
|
||||
This file is part of snapcast
|
||||
Copyright (C) 2014-2021 Johannes Pohl
|
||||
Copyright (C) 2014-2022 Johannes Pohl
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -24,7 +24,9 @@
|
|||
|
||||
// 3rd party headers
|
||||
#include <alsa/asoundlib.h>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
|
||||
namespace streamreader
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/***
|
||||
This file is part of snapcast
|
||||
Copyright (C) 2014-2021 Johannes Pohl
|
||||
Copyright (C) 2014-2022 Johannes Pohl
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -25,7 +25,9 @@
|
|||
#include "pcm_stream.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/read.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <atomic>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/***
|
||||
This file is part of snapcast
|
||||
Copyright (C) 2014-2021 Johannes Pohl
|
||||
Copyright (C) 2014-2022 Johannes Pohl
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -43,7 +43,6 @@
|
|||
#include <vector>
|
||||
|
||||
|
||||
namespace net = boost::asio;
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
@ -180,7 +179,7 @@ protected:
|
|||
/// Send request to stream control script
|
||||
void sendRequest(const std::string& method, const jsonrpcpp::Parameter& params, ResultHandler handler);
|
||||
|
||||
net::strand<net::any_io_executor> strand_;
|
||||
boost::asio::strand<boost::asio::any_io_executor> strand_;
|
||||
std::chrono::time_point<std::chrono::steady_clock> tvEncodedChunk_;
|
||||
std::vector<PcmStream::Listener*> pcmListeners_;
|
||||
StreamUri uri_;
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
#include "common/utils/string_utils.hpp"
|
||||
#include "encoder/encoder_factory.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio/read_until.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <memory>
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#pragma GCC diagnostic ignored "-Wc++11-narrowing"
|
||||
#include <boost/process.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/any_io_executor.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <map>
|
||||
|
@ -41,7 +41,6 @@
|
|||
|
||||
|
||||
namespace bp = boost::process;
|
||||
namespace net = boost::asio;
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/***
|
||||
This file is part of snapcast
|
||||
Copyright (C) 2014-2021 Johannes Pohl
|
||||
Copyright (C) 2014-2022 Johannes Pohl
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -22,6 +22,9 @@
|
|||
// local headers
|
||||
#include "asio_stream.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
namespace streamreader
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
#define WATCH_DOG_HPP
|
||||
|
||||
// 3rd party headers
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/any_io_executor.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
// standard headers
|
||||
#include <memory>
|
||||
|
||||
namespace net = boost::asio;
|
||||
|
||||
namespace streamreader
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue