A TCP server session. More...
#include <ServerSession.h>
Public Types | |
using | callback_function_type = std::function< void(std::shared_ptr< ServerSession >)> |
using | socket_type = boost::asio::ip::tcp::socket |
Public Member Functions | |
void | Close () |
Post a job to close the session. More... | |
stream_id_type | get_stream_id () const |
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 the session is closed. More... | |
ServerSession (boost::asio::io_context &io_context, time_duration timeout, Server &server) | |
void | Write (std::shared_ptr< const Message > message) |
Writes some data to the socket. More... | |
template<typename... Buffers> | |
void | Write (Buffers... buffers) |
Writes some data to the socket. More... | |
Static Public Member Functions | |
template<typename... Buffers> | |
static auto | MakeMessage (Buffers... buffers) |
Private Member Functions | |
void | CloseNow (boost::system::error_code ec=boost::system::error_code()) |
void | StartTimer () |
Private Member Functions inherited from carla::profiler::LifetimeProfiled | |
LifetimeProfiled ()=default | |
Private Member Functions inherited from carla::NonCopyable | |
NonCopyable ()=default | |
NonCopyable (const NonCopyable &)=delete | |
NonCopyable (NonCopyable &&)=delete | |
NonCopyable & | operator= (const NonCopyable &)=delete |
NonCopyable & | operator= (NonCopyable &&)=delete |
Private Attributes | |
boost::asio::deadline_timer | _deadline |
bool | _is_writing = false |
callback_function_type | _on_closed |
Server & | _server |
const size_t | _session_id |
socket_type | _socket |
boost::asio::io_context::strand | _strand |
stream_id_type | _stream_id = 0u |
time_duration | _timeout |
Friends | |
class | Server |
A TCP server session.
When a session opens, it reads from the socket a stream id object and passes itself to the callback functor. The session closes itself after timeout of inactivity is met.
Definition at line 41 of file ServerSession.h.
using carla::streaming::detail::tcp::ServerSession::callback_function_type = std::function<void(std::shared_ptr<ServerSession>)> |
Definition at line 48 of file ServerSession.h.
using carla::streaming::detail::tcp::ServerSession::socket_type = boost::asio::ip::tcp::socket |
Definition at line 47 of file ServerSession.h.
|
explicit |
Definition at line 28 of file ServerSession.cpp.
void carla::streaming::detail::tcp::ServerSession::Close | ( | ) |
Post a job to close the session.
Definition at line 121 of file ServerSession.cpp.
References _strand.
Referenced by StartTimer(), and Write().
|
private |
Definition at line 140 of file ServerSession.cpp.
References _deadline, _on_closed, _session_id, _socket, and carla::log_debug().
Referenced by Open(), and Write().
|
inline |
Definition at line 63 of file ServerSession.h.
References _stream_id.
|
inlinestatic |
Definition at line 68 of file ServerSession.h.
References Write().
Referenced by carla::streaming::detail::MultiStreamState::Write(), and Write().
void carla::streaming::detail::tcp::ServerSession::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 the session is closed.
Definition at line 41 of file ServerSession.cpp.
References _deadline, _on_closed, _session_id, _socket, _strand, _stream_id, _timeout, CloseNow(), DEBUG_ASSERT, DEBUG_ASSERT_EQ, DEBUG_ONLY, carla::log_debug(), carla::log_error(), and StartTimer().
|
private |
Definition at line 125 of file ServerSession.cpp.
References _deadline, _session_id, Close(), and carla::log_debug().
Referenced by Open(), and Write().
void carla::streaming::detail::tcp::ServerSession::Write | ( | std::shared_ptr< const Message > | message | ) |
Writes some data to the socket.
Definition at line 78 of file ServerSession.cpp.
References _deadline, _is_writing, _server, _session_id, _socket, _strand, _timeout, CloseNow(), DEBUG_ASSERT, DEBUG_ASSERT_EQ, DEBUG_ONLY, carla::streaming::detail::tcp::Server::IsSynchronousMode(), carla::log_debug(), and carla::log_info().
Referenced by MakeMessage(), and Write().
|
inline |
Writes some data to the socket.
Definition at line 80 of file ServerSession.h.
References Close(), CloseNow(), MakeMessage(), StartTimer(), and Write().
|
friend |
Definition at line 93 of file ServerSession.h.
|
private |
Definition at line 105 of file ServerSession.h.
Referenced by CloseNow(), Open(), StartTimer(), and Write().
|
private |
Definition at line 111 of file ServerSession.h.
Referenced by Write().
|
private |
Definition at line 109 of file ServerSession.h.
Referenced by CloseNow(), and Open().
|
private |
Definition at line 95 of file ServerSession.h.
Referenced by Write().
|
private |
Definition at line 97 of file ServerSession.h.
Referenced by CloseNow(), Open(), StartTimer(), and Write().
|
private |
Definition at line 101 of file ServerSession.h.
Referenced by CloseNow(), Open(), and Write().
|
private |
Definition at line 107 of file ServerSession.h.
|
private |
Definition at line 99 of file ServerSession.h.
Referenced by get_stream_id(), and Open().
|
private |
Definition at line 103 of file ServerSession.h.