mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-11 08:06:41 +02:00
Use namespace "boost::asio" instead of "net"
This commit is contained in:
parent
989eb6ec8e
commit
4f29f000de
16 changed files with 79 additions and 74 deletions
|
@ -35,7 +35,7 @@ using namespace std;
|
||||||
static constexpr auto LOG_TAG = "Connection";
|
static constexpr auto LOG_TAG = "Connection";
|
||||||
|
|
||||||
ClientConnection::ClientConnection(boost::asio::io_context& io_context, const ClientSettings::Server& server)
|
ClientConnection::ClientConnection(boost::asio::io_context& io_context, const ClientSettings::Server& server)
|
||||||
: io_context_(io_context), strand_(net::make_strand(io_context_.get_executor())), resolver_(strand_), socket_(strand_), reqId_(1), server_(server)
|
: io_context_(io_context), strand_(boost::asio::make_strand(io_context_.get_executor())), resolver_(strand_), socket_(strand_), reqId_(1), server_(server)
|
||||||
{
|
{
|
||||||
base_msg_size_ = base_message_.getSize();
|
base_msg_size_ = base_message_.getSize();
|
||||||
buffer_.resize(base_msg_size_);
|
buffer_.resize(base_msg_size_);
|
||||||
|
@ -144,7 +144,7 @@ void ClientConnection::sendNext()
|
||||||
message.msg->serialize(stream);
|
message.msg->serialize(stream);
|
||||||
auto handler = message.handler;
|
auto handler = message.handler;
|
||||||
|
|
||||||
net::async_write(socket_, streambuf, [this, handler](boost::system::error_code ec, std::size_t length) {
|
boost::asio::async_write(socket_, streambuf, [this, handler](boost::system::error_code ec, std::size_t length) {
|
||||||
if (ec)
|
if (ec)
|
||||||
LOG(ERROR, LOG_TAG) << "Failed to send message, error: " << ec.message() << "\n";
|
LOG(ERROR, LOG_TAG) << "Failed to send message, error: " << ec.message() << "\n";
|
||||||
else
|
else
|
||||||
|
@ -162,7 +162,7 @@ void ClientConnection::sendNext()
|
||||||
|
|
||||||
void ClientConnection::send(const msg::message_ptr& message, const ResultHandler& handler)
|
void ClientConnection::send(const msg::message_ptr& message, const ResultHandler& handler)
|
||||||
{
|
{
|
||||||
net::post(strand_, [this, message, handler]() {
|
boost::asio::post(strand_, [this, message, handler]() {
|
||||||
messages_.emplace_back(message, handler);
|
messages_.emplace_back(message, handler);
|
||||||
if (messages_.size() > 1)
|
if (messages_.size() > 1)
|
||||||
{
|
{
|
||||||
|
@ -176,7 +176,7 @@ void ClientConnection::send(const msg::message_ptr& message, const ResultHandler
|
||||||
|
|
||||||
void ClientConnection::sendRequest(const msg::message_ptr& message, const chronos::usec& timeout, const MessageHandler<msg::BaseMessage>& handler)
|
void ClientConnection::sendRequest(const msg::message_ptr& message, const chronos::usec& timeout, const MessageHandler<msg::BaseMessage>& handler)
|
||||||
{
|
{
|
||||||
net::post(strand_, [this, message, timeout, handler]() {
|
boost::asio::post(strand_, [this, message, timeout, handler]() {
|
||||||
pendingRequests_.erase(
|
pendingRequests_.erase(
|
||||||
std::remove_if(pendingRequests_.begin(), pendingRequests_.end(), [](std::weak_ptr<PendingRequest> request) { return request.expired(); }),
|
std::remove_if(pendingRequests_.begin(), pendingRequests_.end(), [](std::weak_ptr<PendingRequest> request) { return request.expired(); }),
|
||||||
pendingRequests_.end());
|
pendingRequests_.end());
|
||||||
|
@ -197,7 +197,7 @@ void ClientConnection::sendRequest(const msg::message_ptr& message, const chrono
|
||||||
|
|
||||||
void ClientConnection::getNextMessage(const MessageHandler<msg::BaseMessage>& handler)
|
void ClientConnection::getNextMessage(const MessageHandler<msg::BaseMessage>& handler)
|
||||||
{
|
{
|
||||||
net::async_read(socket_, boost::asio::buffer(buffer_, base_msg_size_), [this, handler](boost::system::error_code ec, std::size_t length) mutable {
|
boost::asio::async_read(socket_, boost::asio::buffer(buffer_, base_msg_size_), [this, handler](boost::system::error_code ec, std::size_t length) mutable {
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, LOG_TAG) << "Error reading message header of length " << length << ": " << ec.message() << "\n";
|
LOG(ERROR, LOG_TAG) << "Error reading message header of length " << length << ": " << ec.message() << "\n";
|
||||||
|
@ -229,7 +229,8 @@ void ClientConnection::getNextMessage(const MessageHandler<msg::BaseMessage>& ha
|
||||||
if (base_message_.size > buffer_.size())
|
if (base_message_.size > buffer_.size())
|
||||||
buffer_.resize(base_message_.size);
|
buffer_.resize(base_message_.size);
|
||||||
|
|
||||||
net::async_read(socket_, boost::asio::buffer(buffer_, base_message_.size), [this, handler](boost::system::error_code ec, std::size_t length) mutable {
|
boost::asio::async_read(socket_, boost::asio::buffer(buffer_, base_message_.size),
|
||||||
|
[this, handler](boost::system::error_code ec, std::size_t length) mutable {
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, LOG_TAG) << "Error reading message body of length " << length << ": " << ec.message() << "\n";
|
LOG(ERROR, LOG_TAG) << "Error reading message body of length " << length << ": " << ec.message() << "\n";
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
|
|
||||||
|
|
||||||
using boost::asio::ip::tcp;
|
using boost::asio::ip::tcp;
|
||||||
namespace net = boost::asio;
|
|
||||||
|
|
||||||
|
|
||||||
class ClientConnection;
|
class ClientConnection;
|
||||||
|
@ -52,7 +51,7 @@ using MessageHandler = std::function<void(const boost::system::error_code&, std:
|
||||||
class PendingRequest : public std::enable_shared_from_this<PendingRequest>
|
class PendingRequest : public std::enable_shared_from_this<PendingRequest>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PendingRequest(const net::strand<net::any_io_executor>& strand, uint16_t reqId, const MessageHandler<msg::BaseMessage>& handler)
|
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){};
|
: id_(reqId), timer_(strand), strand_(strand), handler_(handler){};
|
||||||
|
|
||||||
virtual ~PendingRequest()
|
virtual ~PendingRequest()
|
||||||
|
@ -65,7 +64,7 @@ public:
|
||||||
/// @param value the response message
|
/// @param value the response message
|
||||||
void setValue(std::unique_ptr<msg::BaseMessage> value)
|
void setValue(std::unique_ptr<msg::BaseMessage> value)
|
||||||
{
|
{
|
||||||
net::post(strand_, [this, self = shared_from_this(), val = std::move(value)]() mutable {
|
boost::asio::post(strand_, [this, self = shared_from_this(), val = std::move(value)]() mutable {
|
||||||
timer_.cancel();
|
timer_.cancel();
|
||||||
if (handler_)
|
if (handler_)
|
||||||
handler_({}, std::move(val));
|
handler_({}, std::move(val));
|
||||||
|
@ -111,7 +110,7 @@ public:
|
||||||
private:
|
private:
|
||||||
uint16_t id_;
|
uint16_t id_;
|
||||||
boost::asio::steady_timer timer_;
|
boost::asio::steady_timer timer_;
|
||||||
net::strand<net::any_io_executor> strand_;
|
boost::asio::strand<boost::asio::any_io_executor> strand_;
|
||||||
MessageHandler<msg::BaseMessage> handler_;
|
MessageHandler<msg::BaseMessage> handler_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -178,7 +177,7 @@ protected:
|
||||||
size_t base_msg_size_;
|
size_t base_msg_size_;
|
||||||
|
|
||||||
boost::asio::io_context& io_context_;
|
boost::asio::io_context& io_context_;
|
||||||
net::strand<net::any_io_executor> strand_;
|
boost::asio::strand<boost::asio::any_io_executor> strand_;
|
||||||
tcp::resolver resolver_;
|
tcp::resolver resolver_;
|
||||||
tcp::socket socket_;
|
tcp::socket socket_;
|
||||||
std::vector<std::weak_ptr<PendingRequest>> pendingRequests_;
|
std::vector<std::weak_ptr<PendingRequest>> pendingRequests_;
|
||||||
|
|
|
@ -161,7 +161,7 @@ void ControlServer::start()
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LOG(INFO, LOG_TAG) << "Creating TCP acceptor for address: " << address << ", port: " << tcp_settings_.port << "\n";
|
LOG(INFO, LOG_TAG) << "Creating TCP acceptor for address: " << address << ", port: " << tcp_settings_.port << "\n";
|
||||||
acceptor_tcp_.emplace_back(make_unique<tcp::acceptor>(net::make_strand(io_context_.get_executor()),
|
acceptor_tcp_.emplace_back(make_unique<tcp::acceptor>(boost::asio::make_strand(io_context_.get_executor()),
|
||||||
tcp::endpoint(boost::asio::ip::address::from_string(address), tcp_settings_.port)));
|
tcp::endpoint(boost::asio::ip::address::from_string(address), tcp_settings_.port)));
|
||||||
}
|
}
|
||||||
catch (const boost::system::system_error& e)
|
catch (const boost::system::system_error& e)
|
||||||
|
@ -177,7 +177,7 @@ void ControlServer::start()
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LOG(INFO, LOG_TAG) << "Creating HTTP acceptor for address: " << address << ", port: " << http_settings_.port << "\n";
|
LOG(INFO, LOG_TAG) << "Creating HTTP acceptor for address: " << address << ", port: " << http_settings_.port << "\n";
|
||||||
acceptor_http_.emplace_back(make_unique<tcp::acceptor>(net::make_strand(io_context_.get_executor()),
|
acceptor_http_.emplace_back(make_unique<tcp::acceptor>(boost::asio::make_strand(io_context_.get_executor()),
|
||||||
tcp::endpoint(boost::asio::ip::address::from_string(address), http_settings_.port)));
|
tcp::endpoint(boost::asio::ip::address::from_string(address), http_settings_.port)));
|
||||||
}
|
}
|
||||||
catch (const boost::system::system_error& e)
|
catch (const boost::system::system_error& e)
|
||||||
|
|
|
@ -32,7 +32,7 @@ static constexpr auto LOG_TAG = "ControlSessionTCP";
|
||||||
|
|
||||||
|
|
||||||
ControlSessionTcp::ControlSessionTcp(ControlMessageReceiver* receiver, tcp::socket&& socket)
|
ControlSessionTcp::ControlSessionTcp(ControlMessageReceiver* receiver, tcp::socket&& socket)
|
||||||
: ControlSession(receiver), socket_(std::move(socket)), strand_(net::make_strand(socket_.get_executor()))
|
: ControlSession(receiver), socket_(std::move(socket)), strand_(boost::asio::make_strand(socket_.get_executor()))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ void ControlSessionTcp::stop()
|
||||||
|
|
||||||
void ControlSessionTcp::sendAsync(const std::string& message)
|
void ControlSessionTcp::sendAsync(const std::string& message)
|
||||||
{
|
{
|
||||||
net::post(strand_, [this, self = shared_from_this(), message]() {
|
boost::asio::post(strand_, [this, self = shared_from_this(), message]() {
|
||||||
messages_.emplace_back(message + "\r\n");
|
messages_.emplace_back(message + "\r\n");
|
||||||
if (messages_.size() > 1)
|
if (messages_.size() > 1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
using boost::asio::ip::tcp;
|
using boost::asio::ip::tcp;
|
||||||
namespace net = boost::asio;
|
|
||||||
|
|
||||||
/// Endpoint for a connected control client.
|
/// Endpoint for a connected control client.
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +54,7 @@ protected:
|
||||||
|
|
||||||
tcp::socket socket_;
|
tcp::socket socket_;
|
||||||
boost::asio::streambuf streambuf_;
|
boost::asio::streambuf streambuf_;
|
||||||
net::strand<net::any_io_executor> strand_;
|
boost::asio::strand<boost::asio::any_io_executor> strand_;
|
||||||
std::deque<std::string> messages_;
|
std::deque<std::string> messages_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ static constexpr auto LOG_TAG = "ControlSessionWS";
|
||||||
|
|
||||||
|
|
||||||
ControlSessionWebsocket::ControlSessionWebsocket(ControlMessageReceiver* receiver, websocket::stream<beast::tcp_stream>&& socket)
|
ControlSessionWebsocket::ControlSessionWebsocket(ControlMessageReceiver* receiver, websocket::stream<beast::tcp_stream>&& socket)
|
||||||
: ControlSession(receiver), ws_(std::move(socket)), strand_(net::make_strand(ws_.get_executor()))
|
: ControlSession(receiver), ws_(std::move(socket)), strand_(boost::asio::make_strand(ws_.get_executor()))
|
||||||
{
|
{
|
||||||
LOG(DEBUG, LOG_TAG) << "ControlSessionWebsocket\n";
|
LOG(DEBUG, LOG_TAG) << "ControlSessionWebsocket\n";
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ void ControlSessionWebsocket::stop()
|
||||||
|
|
||||||
void ControlSessionWebsocket::sendAsync(const std::string& message)
|
void ControlSessionWebsocket::sendAsync(const std::string& message)
|
||||||
{
|
{
|
||||||
net::post(strand_, [this, self = shared_from_this(), msg = message]() {
|
boost::asio::post(strand_, [this, self = shared_from_this(), msg = message]() {
|
||||||
messages_.push_back(std::move(msg));
|
messages_.push_back(std::move(msg));
|
||||||
if (messages_.size() > 1)
|
if (messages_.size() > 1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,9 +29,9 @@
|
||||||
// standard headers
|
// standard headers
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
|
|
||||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
/// Endpoint for a connected control client.
|
/// Endpoint for a connected control client.
|
||||||
|
@ -62,7 +62,7 @@ protected:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
beast::flat_buffer buffer_;
|
beast::flat_buffer buffer_;
|
||||||
net::strand<net::any_io_executor> strand_;
|
boost::asio::strand<boost::asio::any_io_executor> strand_;
|
||||||
std::deque<std::string> messages_;
|
std::deque<std::string> messages_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***
|
/***
|
||||||
This file is part of snapcast
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -39,7 +39,7 @@ using json = nlohmann::json;
|
||||||
|
|
||||||
static constexpr auto LOG_TAG = "StreamServer";
|
static constexpr auto LOG_TAG = "StreamServer";
|
||||||
|
|
||||||
StreamServer::StreamServer(net::io_context& io_context, const ServerSettings& serverSettings, StreamMessageReceiver* messageReceiver)
|
StreamServer::StreamServer(boost::asio::io_context& io_context, const ServerSettings& serverSettings, StreamMessageReceiver* messageReceiver)
|
||||||
: io_context_(io_context), config_timer_(io_context), settings_(serverSettings), messageReceiver_(messageReceiver)
|
: io_context_(io_context), config_timer_(io_context), settings_(serverSettings), messageReceiver_(messageReceiver)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ void StreamServer::start()
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LOG(INFO, LOG_TAG) << "Creating stream acceptor for address: " << address << ", port: " << settings_.stream.port << "\n";
|
LOG(INFO, LOG_TAG) << "Creating stream acceptor for address: " << address << ", port: " << settings_.stream.port << "\n";
|
||||||
acceptor_.emplace_back(make_unique<tcp::acceptor>(net::make_strand(io_context_.get_executor()),
|
acceptor_.emplace_back(make_unique<tcp::acceptor>(boost::asio::make_strand(io_context_.get_executor()),
|
||||||
tcp::endpoint(boost::asio::ip::address::from_string(address), settings_.stream.port)));
|
tcp::endpoint(boost::asio::ip::address::from_string(address), settings_.stream.port)));
|
||||||
}
|
}
|
||||||
catch (const boost::system::system_error& e)
|
catch (const boost::system::system_error& e)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***
|
/***
|
||||||
This file is part of snapcast
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -59,7 +59,7 @@ using session_ptr = std::shared_ptr<StreamSession>;
|
||||||
class StreamServer : public StreamMessageReceiver
|
class StreamServer : public StreamMessageReceiver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StreamServer(net::io_context& io_context, const ServerSettings& serverSettings, StreamMessageReceiver* messageReceiver = nullptr);
|
StreamServer(boost::asio::io_context& io_context, const ServerSettings& serverSettings, StreamMessageReceiver* messageReceiver = nullptr);
|
||||||
virtual ~StreamServer();
|
virtual ~StreamServer();
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
@ -87,7 +87,7 @@ private:
|
||||||
mutable std::recursive_mutex sessionsMutex_;
|
mutable std::recursive_mutex sessionsMutex_;
|
||||||
// mutable std::recursive_mutex clientMutex_;
|
// mutable std::recursive_mutex clientMutex_;
|
||||||
std::vector<std::weak_ptr<StreamSession>> sessions_;
|
std::vector<std::weak_ptr<StreamSession>> sessions_;
|
||||||
net::io_context& io_context_;
|
boost::asio::io_context& io_context_;
|
||||||
std::vector<acceptor_ptr> acceptor_;
|
std::vector<acceptor_ptr> acceptor_;
|
||||||
boost::asio::steady_timer config_timer_;
|
boost::asio::steady_timer config_timer_;
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,16 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
***/
|
***/
|
||||||
|
|
||||||
|
// prototype/interface header file
|
||||||
#include "stream_session.hpp"
|
#include "stream_session.hpp"
|
||||||
|
|
||||||
|
// local headers
|
||||||
#include "common/aixlog.hpp"
|
#include "common/aixlog.hpp"
|
||||||
#include "message/pcm_chunk.hpp"
|
#include "message/pcm_chunk.hpp"
|
||||||
|
|
||||||
|
// 3rd party headers
|
||||||
|
|
||||||
|
// standard headers
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -28,8 +34,8 @@ using namespace streamreader;
|
||||||
static constexpr auto LOG_TAG = "StreamSession";
|
static constexpr auto LOG_TAG = "StreamSession";
|
||||||
|
|
||||||
|
|
||||||
StreamSession::StreamSession(const net::any_io_executor& executor, StreamMessageReceiver* receiver)
|
StreamSession::StreamSession(const boost::asio::any_io_executor& executor, StreamMessageReceiver* receiver)
|
||||||
: messageReceiver_(receiver), pcmStream_(nullptr), strand_(net::make_strand(executor))
|
: messageReceiver_(receiver), pcmStream_(nullptr), strand_(boost::asio::make_strand(executor))
|
||||||
{
|
{
|
||||||
base_msg_size_ = baseMessage_.getSize();
|
base_msg_size_ = baseMessage_.getSize();
|
||||||
buffer_.resize(base_msg_size_);
|
buffer_.resize(base_msg_size_);
|
||||||
|
@ -54,7 +60,7 @@ void StreamSession::send_next()
|
||||||
{
|
{
|
||||||
auto& buffer = messages_.front();
|
auto& buffer = messages_.front();
|
||||||
buffer.on_air = true;
|
buffer.on_air = true;
|
||||||
net::post(strand_, [this, self = shared_from_this(), buffer]() {
|
boost::asio::post(strand_, [this, self = shared_from_this(), buffer]() {
|
||||||
sendAsync(buffer, [this](boost::system::error_code ec, std::size_t length) {
|
sendAsync(buffer, [this](boost::system::error_code ec, std::size_t length) {
|
||||||
messages_.pop_front();
|
messages_.pop_front();
|
||||||
if (ec)
|
if (ec)
|
||||||
|
@ -72,7 +78,7 @@ void StreamSession::send_next()
|
||||||
|
|
||||||
void StreamSession::send(shared_const_buffer const_buf)
|
void StreamSession::send(shared_const_buffer const_buf)
|
||||||
{
|
{
|
||||||
net::post(strand_, [this, self = shared_from_this(), const_buf]() {
|
boost::asio::post(strand_, [this, self = shared_from_this(), const_buf]() {
|
||||||
// delete PCM chunks that are older than the overall buffer duration
|
// delete PCM chunks that are older than the overall buffer duration
|
||||||
messages_.erase(std::remove_if(messages_.begin(), messages_.end(),
|
messages_.erase(std::remove_if(messages_.begin(), messages_.end(),
|
||||||
[this](const shared_const_buffer& buffer) {
|
[this](const shared_const_buffer& buffer) {
|
||||||
|
|
|
@ -122,7 +122,7 @@ class StreamSession : public std::enable_shared_from_this<StreamSession>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// ctor. Received message from the client are passed to StreamMessageReceiver
|
/// ctor. Received message from the client are passed to StreamMessageReceiver
|
||||||
StreamSession(const net::any_io_executor& executor, StreamMessageReceiver* receiver);
|
StreamSession(const boost::asio::any_io_executor& executor, StreamMessageReceiver* receiver);
|
||||||
virtual ~StreamSession() = default;
|
virtual ~StreamSession() = default;
|
||||||
|
|
||||||
virtual std::string getIP() = 0;
|
virtual std::string getIP() = 0;
|
||||||
|
@ -162,7 +162,7 @@ protected:
|
||||||
StreamMessageReceiver* messageReceiver_;
|
StreamMessageReceiver* messageReceiver_;
|
||||||
size_t bufferMs_;
|
size_t bufferMs_;
|
||||||
streamreader::PcmStreamPtr pcmStream_;
|
streamreader::PcmStreamPtr pcmStream_;
|
||||||
net::strand<net::any_io_executor> strand_;
|
boost::asio::strand<boost::asio::any_io_executor> strand_;
|
||||||
std::deque<shared_const_buffer> messages_;
|
std::deque<shared_const_buffer> messages_;
|
||||||
mutable std::mutex mutex_;
|
mutable std::mutex mutex_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***
|
/***
|
||||||
This file is part of snapcast
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -45,7 +45,7 @@ static constexpr auto LOG_TAG = "PcmStream";
|
||||||
|
|
||||||
|
|
||||||
PcmStream::PcmStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
|
PcmStream::PcmStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
|
||||||
: active_(false), strand_(net::make_strand(ioc.get_executor())), pcmListeners_{pcmListener}, uri_(uri), chunk_ms_(20), state_(ReaderState::kIdle),
|
: active_(false), strand_(boost::asio::make_strand(ioc.get_executor())), pcmListeners_{pcmListener}, uri_(uri), chunk_ms_(20), state_(ReaderState::kIdle),
|
||||||
ioc_(ioc), server_settings_(server_settings), req_id_(0), property_timer_(strand_)
|
ioc_(ioc), server_settings_(server_settings), req_id_(0), property_timer_(strand_)
|
||||||
{
|
{
|
||||||
encoder::EncoderFactory encoderFactory;
|
encoder::EncoderFactory encoderFactory;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***
|
/***
|
||||||
This file is part of snapcast
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -39,7 +39,7 @@ namespace streamreader
|
||||||
static constexpr auto LOG_TAG = "Script";
|
static constexpr auto LOG_TAG = "Script";
|
||||||
|
|
||||||
|
|
||||||
StreamControl::StreamControl(const net::any_io_executor& executor) : executor_(executor)
|
StreamControl::StreamControl(const boost::asio::any_io_executor& executor) : executor_(executor)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ void StreamControl::start(const std::string& stream_id, const ServerSettings& se
|
||||||
void StreamControl::command(const jsonrpcpp::Request& request, const OnResponse& response_handler)
|
void StreamControl::command(const jsonrpcpp::Request& request, const OnResponse& response_handler)
|
||||||
{
|
{
|
||||||
// use strand to serialize commands sent from different threads
|
// use strand to serialize commands sent from different threads
|
||||||
net::post(executor_, [this, request, response_handler]() {
|
boost::asio::post(executor_, [this, request, response_handler]() {
|
||||||
if (response_handler)
|
if (response_handler)
|
||||||
request_callbacks_[request.id()] = response_handler;
|
request_callbacks_[request.id()] = response_handler;
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ void StreamControl::onLog(std::string message)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ScriptStreamControl::ScriptStreamControl(const net::any_io_executor& executor, const std::string& script) : StreamControl(executor), script_(script)
|
ScriptStreamControl::ScriptStreamControl(const boost::asio::any_io_executor& executor, const std::string& script) : StreamControl(executor), script_(script)
|
||||||
{
|
{
|
||||||
namespace fs = utils::file;
|
namespace fs = utils::file;
|
||||||
if (!fs::exists(script_))
|
if (!fs::exists(script_))
|
||||||
|
@ -194,7 +194,7 @@ void ScriptStreamControl::doCommand(const jsonrpcpp::Request& request)
|
||||||
void ScriptStreamControl::stderrReadLine()
|
void ScriptStreamControl::stderrReadLine()
|
||||||
{
|
{
|
||||||
const std::string delimiter = "\n";
|
const std::string delimiter = "\n";
|
||||||
net::async_read_until(*stream_stderr_, streambuf_stderr_, delimiter, [this, delimiter](const std::error_code& ec, std::size_t bytes_transferred) {
|
boost::asio::async_read_until(*stream_stderr_, streambuf_stderr_, delimiter, [this, delimiter](const std::error_code& ec, std::size_t bytes_transferred) {
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, LOG_TAG) << "Error while reading from stderr: " << ec.message() << "\n";
|
LOG(ERROR, LOG_TAG) << "Error while reading from stderr: " << ec.message() << "\n";
|
||||||
|
@ -214,7 +214,7 @@ void ScriptStreamControl::stderrReadLine()
|
||||||
void ScriptStreamControl::stdoutReadLine()
|
void ScriptStreamControl::stdoutReadLine()
|
||||||
{
|
{
|
||||||
const std::string delimiter = "\n";
|
const std::string delimiter = "\n";
|
||||||
net::async_read_until(*stream_stdout_, streambuf_stdout_, delimiter, [this, delimiter](const std::error_code& ec, std::size_t bytes_transferred) {
|
boost::asio::async_read_until(*stream_stdout_, streambuf_stdout_, delimiter, [this, delimiter](const std::error_code& ec, std::size_t bytes_transferred) {
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, LOG_TAG) << "Error while reading from stdout: " << ec.message() << "\n";
|
LOG(ERROR, LOG_TAG) << "Error while reading from stdout: " << ec.message() << "\n";
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***
|
/***
|
||||||
This file is part of snapcast
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -58,7 +58,7 @@ public:
|
||||||
using OnResponse = std::function<void(const jsonrpcpp::Response& response)>;
|
using OnResponse = std::function<void(const jsonrpcpp::Response& response)>;
|
||||||
using OnLog = std::function<void(std::string message)>;
|
using OnLog = std::function<void(std::string message)>;
|
||||||
|
|
||||||
StreamControl(const net::any_io_executor& executor);
|
StreamControl(const boost::asio::any_io_executor& executor);
|
||||||
virtual ~StreamControl();
|
virtual ~StreamControl();
|
||||||
|
|
||||||
void start(const std::string& stream_id, const ServerSettings& server_setttings, const OnNotification& notification_handler,
|
void start(const std::string& stream_id, const ServerSettings& server_setttings, const OnNotification& notification_handler,
|
||||||
|
@ -74,7 +74,7 @@ protected:
|
||||||
void onReceive(const std::string& json);
|
void onReceive(const std::string& json);
|
||||||
void onLog(std::string message);
|
void onLog(std::string message);
|
||||||
|
|
||||||
net::any_io_executor executor_;
|
boost::asio::any_io_executor executor_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OnRequest request_handler_;
|
OnRequest request_handler_;
|
||||||
|
@ -88,7 +88,7 @@ private:
|
||||||
class ScriptStreamControl : public StreamControl
|
class ScriptStreamControl : public StreamControl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScriptStreamControl(const net::any_io_executor& executor, const std::string& script);
|
ScriptStreamControl(const boost::asio::any_io_executor& executor, const std::string& script);
|
||||||
virtual ~ScriptStreamControl() = default;
|
virtual ~ScriptStreamControl() = default;
|
||||||
|
|
||||||
void stop() override;
|
void stop() override;
|
||||||
|
|
|
@ -36,7 +36,7 @@ using namespace std;
|
||||||
namespace streamreader
|
namespace streamreader
|
||||||
{
|
{
|
||||||
|
|
||||||
Watchdog::Watchdog(const net::any_io_executor& executor, WatchdogListener* listener) : timer_(executor), listener_(listener)
|
Watchdog::Watchdog(const boost::asio::any_io_executor& executor, WatchdogListener* listener) : timer_(executor), listener_(listener)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
class Watchdog
|
class Watchdog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Watchdog(const net::any_io_executor& executor, WatchdogListener* listener = nullptr);
|
Watchdog(const boost::asio::any_io_executor& executor, WatchdogListener* listener = nullptr);
|
||||||
virtual ~Watchdog();
|
virtual ~Watchdog();
|
||||||
|
|
||||||
void start(const std::chrono::milliseconds& timeout);
|
void start(const std::chrono::milliseconds& timeout);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue