13 #include <boost/asio/read.hpp> 14 #include <boost/asio/write.hpp> 15 #include <boost/asio/bind_executor.hpp> 16 #include <boost/asio/post.hpp> 29 boost::asio::io_context &io_context,
38 _deadline(io_context),
39 _strand(io_context) {}
49 const boost::asio::ip::tcp::no_delay option(
true);
53 auto self = shared_from_this();
54 boost::asio::post(
_strand, [=]() {
56 auto handle_query = [
this,
self, callback=std::move(on_opened)](
57 const boost::system::error_code &ec,
62 boost::asio::post(
_strand.context(), [=]() { callback(
self); });
71 boost::asio::async_read(
74 boost::asio::bind_executor(
_strand, handle_query));
81 auto self = shared_from_this();
82 boost::asio::post(
_strand, [=]() {
90 std::this_thread::yield();
100 auto handle_sent = [
this,
self, message](
const boost::system::error_code &ec,
size_t DEBUG_ONLY(bytes)) {
114 boost::asio::async_write(
116 message->GetBufferSequence(),
122 boost::asio::post(
_strand, [
self=shared_from_this()]() {
self->CloseNow(); });
126 if (
_deadline.expires_at() <= boost::asio::deadline_timer::traits_type::now()) {
130 _deadline.async_wait([
this,
self=shared_from_this()](boost::system::error_code ec) {
145 boost::system::error_code ec2;
146 _socket.shutdown(boost::asio::socket_base::shutdown_both, ec2);
callback_function_type _on_closed
static void log_error(Args &&... args)
void CloseNow(boost::system::error_code ec=boost::system::error_code())
This file contains definitions of common data structures used in traffic manager. ...
void Close()
Post a job to close the session.
static void log_debug(Args &&...)
#define DEBUG_ASSERT_EQ(lhs, rhs)
#define DEBUG_ASSERT(predicate)
#define LIBCARLA_INITIALIZE_LIFETIME_PROFILER(display_name)
uint32_t message_size_type
std::function< void(std::shared_ptr< ServerSession >)> callback_function_type
bool IsSynchronousMode() const
void Write(std::shared_ptr< const Message > message)
Writes some data to the socket.
static void log_info(Args &&... args)
static std::atomic_size_t SESSION_COUNTER
Positive time duration up to milliseconds resolution.
boost::asio::deadline_timer _deadline
stream_id_type _stream_id
void Open(callback_function_type on_opened, callback_function_type on_closed)
Starts the session and calls on_opened after successfully reading the stream id, and on_closed once t...
ServerSession(boost::asio::io_context &io_context, time_duration timeout, Server &server)
boost::asio::io_context::strand _strand