CARLA
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
carla::multigpu::Primary Class Reference

A TCP server session. More...

#include <primary.h>

+ Inheritance diagram for carla::multigpu::Primary:

Public Types

using socket_type = boost::asio::ip::tcp::socket
 

Public Member Functions

void Close ()
 Post a job to close the session.
 
void Open (Listener::callback_function_type on_opened, Listener::callback_function_type on_closed, Listener::callback_function_type_response on_response)
 Starts the session and calls on_opened after successfully reading the stream id, and on_closed once the session is closed.
 
 Primary (boost::asio::io_context &io_context, time_duration timeout, Listener &server)
 
void ReadData ()
 read data
 
template<typename... Buffers>
void Write (Buffers... buffers)
 Writes some data to the socket.
 
void Write (std::shared_ptr< const carla::streaming::detail::tcp::Message > message)
 Writes some data to the socket.
 
void Write (std::string text)
 Writes a string.
 
 ~Primary ()
 

Static Public Member Functions

template<typename... Buffers>
static auto MakeMessage (Buffers... buffers)
 

Private Types

using message_type = std::shared_ptr< const carla::streaming::detail::tcp::Message >
 

Private Member Functions

void CloseNow (boost::system::error_code ec=boost::system::error_code())
 
void StartTimer ()
 
void WriteNext ()
 Starts writing the front of the write queue. Strand only.
 
- 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

std::shared_ptr< BufferPool > _buffer_pool
 
boost::asio::steady_timer _deadline
 
bool _is_writing = false
 
Listener::callback_function_type _on_closed
 
Listener::callback_function_type_response _on_response
 
Listener & _server
 
const size_t _session_id
 
socket_type _socket
 
boost::asio::io_context::strand _strand
 
time_duration _timeout
 
std::deque< message_type > _write_queue
 Messages waiting to be written, oldest first, and whether one is being written.
 

Friends

class Listener
 

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 32 of file primary.h.

Member Typedef Documentation

◆ message_type

Definition at line 82 of file primary.h.

◆ socket_type

using carla::multigpu::Primary::socket_type = boost::asio::ip::tcp::socket

Definition at line 38 of file primary.h.

Constructor & Destructor Documentation

◆ Primary()

carla::multigpu::Primary::Primary ( boost::asio::io_context &  io_context,
time_duration  timeout,
Listener &  server 
)
explicit

Definition at line 30 of file primary.cpp.

◆ ~Primary()

carla::multigpu::Primary::~Primary ( )

Definition at line 44 of file primary.cpp.

References _socket.

Member Function Documentation

◆ Close()

void carla::multigpu::Primary::Close ( )

Post a job to close the session.

Definition at line 188 of file primary.cpp.

References _strand.

Referenced by StartTimer().

◆ CloseNow()

void carla::multigpu::Primary::CloseNow ( boost::system::error_code  ec = boost::system::error_code())
private

Definition at line 215 of file primary.cpp.

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

◆ MakeMessage()

template<typename... Buffers>
static auto carla::multigpu::Primary::MakeMessage ( Buffers...  buffers)
inlinestatic

◆ Open()

void carla::multigpu::Primary::Open ( Listener::callback_function_type  on_opened,
Listener::callback_function_type  on_closed,
Listener::callback_function_type_response  on_response 
)

Starts the session and calls on_opened after successfully reading the stream id, and on_closed once the session is closed.

Definition at line 52 of file primary.cpp.

References _on_closed, _on_response, _socket, DEBUG_ASSERT, carla::multigpu::EnableKeepAlive(), and ReadData().

◆ ReadData()

void carla::multigpu::Primary::ReadData ( )

read data

Definition at line 130 of file primary.cpp.

References _strand, DEBUG_ASSERT_EQ, DEBUG_ASSERT_NE, DEBUG_ONLY, carla::multigpu::kMaxMultiGpuMessageBytes, and carla::log_error().

Referenced by Open().

◆ StartTimer()

void carla::multigpu::Primary::StartTimer ( )
private

Definition at line 197 of file primary.cpp.

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

◆ Write() [1/3]

template<typename... Buffers>
void carla::multigpu::Primary::Write ( Buffers...  buffers)
inline

Writes some data to the socket.

Definition at line 73 of file primary.h.

References MakeMessage(), and Write().

◆ Write() [2/3]

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

Writes some data to the socket.

Definition at line 72 of file primary.cpp.

References _strand, and DEBUG_ASSERT.

Referenced by Write(), and Write().

◆ Write() [3/3]

void carla::multigpu::Primary::Write ( std::string  text)

Writes a string.

Definition at line 124 of file primary.cpp.

References carla::BufferView::CreateFrom(), MakeMessage(), and Write().

◆ WriteNext()

void carla::multigpu::Primary::WriteNext ( )
private

Starts writing the front of the write queue. Strand only.

Definition at line 89 of file primary.cpp.

References _deadline, _is_writing, _socket, _strand, _timeout, _write_queue, carla::log_error(), and carla::time_duration::to_chrono().

Friends And Related Symbol Documentation

◆ Listener

friend class Listener
friend

Definition at line 91 of file primary.h.

Member Data Documentation

◆ _buffer_pool

std::shared_ptr<BufferPool> carla::multigpu::Primary::_buffer_pool
private

Definition at line 109 of file primary.h.

◆ _deadline

boost::asio::steady_timer carla::multigpu::Primary::_deadline
private

Definition at line 101 of file primary.h.

Referenced by CloseNow(), StartTimer(), and WriteNext().

◆ _is_writing

bool carla::multigpu::Primary::_is_writing = false
private

Definition at line 116 of file primary.h.

Referenced by WriteNext().

◆ _on_closed

Listener::callback_function_type carla::multigpu::Primary::_on_closed
private

Definition at line 105 of file primary.h.

Referenced by CloseNow(), and Open().

◆ _on_response

Listener::callback_function_type_response carla::multigpu::Primary::_on_response
private

Definition at line 107 of file primary.h.

Referenced by Open().

◆ _server

Listener& carla::multigpu::Primary::_server
private

Definition at line 93 of file primary.h.

◆ _session_id

const size_t carla::multigpu::Primary::_session_id
private

Definition at line 95 of file primary.h.

Referenced by CloseNow(), and StartTimer().

◆ _socket

socket_type carla::multigpu::Primary::_socket
private

Definition at line 97 of file primary.h.

Referenced by CloseNow(), Open(), WriteNext(), and ~Primary().

◆ _strand

boost::asio::io_context::strand carla::multigpu::Primary::_strand
private

Definition at line 103 of file primary.h.

Referenced by Close(), ReadData(), Write(), and WriteNext().

◆ _timeout

time_duration carla::multigpu::Primary::_timeout
private

Definition at line 99 of file primary.h.

Referenced by WriteNext().

◆ _write_queue

std::deque<message_type> carla::multigpu::Primary::_write_queue
private

Messages waiting to be written, oldest first, and whether one is being written.

Strand only: a single write is ever in flight, so two large frames can never interleave on the socket.

Definition at line 114 of file primary.h.

Referenced by WriteNext().


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