10#include <boost/asio/post.hpp>
46 : _io_context(io_context),
47 _acceptor(_io_context,
std::move(ep)),
71 using boost::system::error_code;
74 auto session = std::make_shared<Primary>(
_io_context, timeout, *
this);
75 auto self = shared_from_this();
78 auto handle_query = [on_opened, on_closed, on_response, session, self](
const error_code &ec) {
81 session->Open(std::move(on_opened), std::move(on_closed), std::move(on_response));
84 log_error(
"Secondary server:", ec.message());
88 _acceptor.async_accept(session->_socket, [=](error_code ec) {
90 boost::asio::post(_io_context, [=]() { handle_query(ec); });
91 OpenSession(timeout, on_opened, on_closed, on_response);
警告:在它的io_context停止之前,这个服务器不能被销毁。
boost::asio::io_context & _io_context
boost::asio::ip::tcp::endpoint endpoint
boost::asio::ip::tcp::acceptor _acceptor
std::function< void(std::shared_ptr< Primary >)> callback_function_type
std::function< void(std::shared_ptr< Primary >, carla::Buffer)> callback_function_type_response
Listener(boost::asio::io_context &io_context, endpoint ep)
void OpenSession(time_duration timeout, callback_function_type on_opened, callback_function_type on_closed, callback_function_type_response on_response)
Positive time duration up to milliseconds resolution.
static void log_error(Args &&... args)