CARLA
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
carla::streaming::detail::tcp::ServerSession Class Reference

A TCP server session. More...

#include <ServerSession.h>

+ Inheritance diagram for carla::streaming::detail::tcp::ServerSession:
+ Collaboration diagram for carla::streaming::detail::tcp::ServerSession:

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
 
NonCopyableoperator= (const NonCopyable &)=delete
 
NonCopyableoperator= (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
 

Detailed Description

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.

Member Typedef Documentation

◆ callback_function_type

Definition at line 48 of file ServerSession.h.

◆ socket_type

using carla::streaming::detail::tcp::ServerSession::socket_type = boost::asio::ip::tcp::socket

Definition at line 47 of file ServerSession.h.

Constructor & Destructor Documentation

◆ ServerSession()

carla::streaming::detail::tcp::ServerSession::ServerSession ( boost::asio::io_context &  io_context,
time_duration  timeout,
Server server 
)
explicit

Definition at line 28 of file ServerSession.cpp.

Member Function Documentation

◆ Close()

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().

+ Here is the caller graph for this function:

◆ CloseNow()

void carla::streaming::detail::tcp::ServerSession::CloseNow ( boost::system::error_code  ec = boost::system::error_code())
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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_stream_id()

stream_id_type carla::streaming::detail::tcp::ServerSession::get_stream_id ( ) const
inline
Warning
This function should only be called after the session is opened. It is safe to call this function from within the callback.

Definition at line 63 of file ServerSession.h.

References _stream_id.

◆ MakeMessage()

template<typename... Buffers>
static auto carla::streaming::detail::tcp::ServerSession::MakeMessage ( Buffers...  buffers)
inlinestatic

Definition at line 68 of file ServerSession.h.

References Write().

Referenced by carla::streaming::detail::MultiStreamState::Write(), and Write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Open()

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().

+ Here is the call graph for this function:

◆ StartTimer()

void carla::streaming::detail::tcp::ServerSession::StartTimer ( )
private

Definition at line 125 of file ServerSession.cpp.

References _deadline, _session_id, Close(), and carla::log_debug().

Referenced by Open(), and Write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Write() [1/2]

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Write() [2/2]

template<typename... Buffers>
void carla::streaming::detail::tcp::ServerSession::Write ( Buffers...  buffers)
inline

Writes some data to the socket.

Definition at line 80 of file ServerSession.h.

References Close(), CloseNow(), MakeMessage(), StartTimer(), and Write().

+ Here is the call graph for this function:

Friends And Related Function Documentation

◆ Server

friend class Server
friend

Definition at line 93 of file ServerSession.h.

Member Data Documentation

◆ _deadline

boost::asio::deadline_timer carla::streaming::detail::tcp::ServerSession::_deadline
private

Definition at line 105 of file ServerSession.h.

Referenced by CloseNow(), Open(), StartTimer(), and Write().

◆ _is_writing

bool carla::streaming::detail::tcp::ServerSession::_is_writing = false
private

Definition at line 111 of file ServerSession.h.

Referenced by Write().

◆ _on_closed

callback_function_type carla::streaming::detail::tcp::ServerSession::_on_closed
private

Definition at line 109 of file ServerSession.h.

Referenced by CloseNow(), and Open().

◆ _server

Server& carla::streaming::detail::tcp::ServerSession::_server
private

Definition at line 95 of file ServerSession.h.

Referenced by Write().

◆ _session_id

const size_t carla::streaming::detail::tcp::ServerSession::_session_id
private

Definition at line 97 of file ServerSession.h.

Referenced by CloseNow(), Open(), StartTimer(), and Write().

◆ _socket

socket_type carla::streaming::detail::tcp::ServerSession::_socket
private

Definition at line 101 of file ServerSession.h.

Referenced by CloseNow(), Open(), and Write().

◆ _strand

boost::asio::io_context::strand carla::streaming::detail::tcp::ServerSession::_strand
private

Definition at line 107 of file ServerSession.h.

Referenced by Close(), Open(), and Write().

◆ _stream_id

stream_id_type carla::streaming::detail::tcp::ServerSession::_stream_id = 0u
private

Definition at line 99 of file ServerSession.h.

Referenced by get_stream_id(), and Open().

◆ _timeout

time_duration carla::streaming::detail::tcp::ServerSession::_timeout
private

Definition at line 103 of file ServerSession.h.

Referenced by Open(), and Write().


The documentation for this class was generated from the following files: