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>
30 boost::asio::io_context &io_context,
39 _deadline(io_context,
std::chrono::steady_clock::time_point::max()),
40 _strand(io_context) {}
50 const boost::asio::ip::tcp::no_delay option(
true);
54 auto self = shared_from_this();
55 boost::asio::post(
_strand, [=]() {
57 auto handle_query = [
this, self, callback=std::move(on_opened)](
58 const boost::system::error_code &ec,
63 boost::asio::post(
_strand.context(), [=]() { callback(self); });
72 boost::asio::async_read(
75 boost::asio::bind_executor(
_strand, handle_query));
82 auto self = shared_from_this();
90 std::this_thread::sleep_for(std::chrono::microseconds(100));
100 auto handle_sent = [
this, self, message](
const boost::system::error_code &ec,
size_t DEBUG_ONLY(bytes)) {
114 boost::asio::async_write(
_socket, message->GetBufferSequence(),
115 boost::asio::bind_executor(
_strand, handle_sent));
119 boost::asio::post(
_strand, [self=shared_from_this()]() { self->CloseNow(); });
123 if (
_deadline.expiry() <= std::chrono::steady_clock::now()) {
127 _deadline.async_wait([
this, self=shared_from_this()](boost::system::error_code ec) {
143 boost::system::error_code ec2;
144 _socket.shutdown(boost::asio::socket_base::shutdown_both, ec2);
#define DEBUG_ASSERT(predicate)
#define DEBUG_ASSERT_EQ(lhs, rhs)
#define LIBCARLA_INITIALIZE_LIFETIME_PROFILER(display_name)
void CloseNow(boost::system::error_code ec=boost::system::error_code())
void Close()
Post a job to close the session.
ServerSession(boost::asio::io_context &io_context, time_duration timeout, Server &server)
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...
callback_function_type _on_closed
boost::asio::io_context::strand _strand
boost::asio::steady_timer _deadline
stream_id_type _stream_id
std::function< void(std::shared_ptr< ServerSession >)> callback_function_type
std::atomic_bool _is_closed
void Write(std::shared_ptr< const Message > message)
Writes some data to the socket.
bool IsSynchronousMode() const
Positive time duration up to milliseconds resolution.
constexpr auto to_chrono() const
static std::atomic_size_t SESSION_COUNTER
uint32_t message_size_type
This file contains definitions of common data structures used in traffic manager.
static void log_error(Args &&... args)
static void log_info(Args &&... args)
static void log_debug(Args &&... args)