CARLA
Loading...
Searching...
No Matches
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:

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.
 
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.
 
 ServerSession (boost::asio::io_context &io_context, time_duration timeout, Server &server)
 
template<typename... Buffers>
void Write (Buffers... buffers)
 Writes some data to the socket.
 
void Write (std::shared_ptr< const Message > message)
 Writes some data to the socket.
 

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::steady_timer _deadline
 
std::atomic_bool _is_closed {false}
 
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 42 of file ServerSession.h.

Member Typedef Documentation

◆ callback_function_type

Definition at line 49 of file ServerSession.h.

◆ socket_type

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

Definition at line 48 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 29 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 118 of file ServerSession.cpp.

References _strand.

Referenced by StartTimer().

◆ CloseNow()

void carla::streaming::detail::tcp::ServerSession::CloseNow ( boost::system::error_code  ec = boost::system::error_code())
private

Definition at line 137 of file ServerSession.cpp.

References _deadline, _is_closed, _on_closed, _session_id, _socket, and carla::log_debug().

Referenced by Open(), and Write().

◆ 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 64 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 69 of file ServerSession.h.

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

◆ 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 42 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(), StartTimer(), and carla::time_duration::to_chrono().

◆ StartTimer()

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

Definition at line 122 of file ServerSession.cpp.

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

Referenced by Open(), and StartTimer().

◆ Write() [1/2]

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

Writes some data to the socket.

Definition at line 81 of file ServerSession.h.

References MakeMessage(), and Write().

◆ Write() [2/2]

void carla::streaming::detail::tcp::ServerSession::Write ( std::shared_ptr< const Message >  message)

Friends And Related Symbol Documentation

◆ Server

friend class Server
friend

Definition at line 94 of file ServerSession.h.

Member Data Documentation

◆ _deadline

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

Definition at line 106 of file ServerSession.h.

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

◆ _is_closed

std::atomic_bool carla::streaming::detail::tcp::ServerSession::_is_closed {false}
private

Definition at line 113 of file ServerSession.h.

Referenced by CloseNow().

◆ _is_writing

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

Definition at line 112 of file ServerSession.h.

Referenced by Write().

◆ _on_closed

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

Definition at line 110 of file ServerSession.h.

Referenced by CloseNow(), and Open().

◆ _server

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

Definition at line 96 of file ServerSession.h.

Referenced by Write().

◆ _session_id

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

Definition at line 98 of file ServerSession.h.

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

◆ _socket

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

Definition at line 102 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 108 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 100 of file ServerSession.h.

Referenced by get_stream_id(), and Open().

◆ _timeout

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

Definition at line 104 of file ServerSession.h.

Referenced by Open(), and Write().


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