srs-control 0.2.2
Loading...
Searching...
No Matches
srs::connection::SpecialSocket Class Reference

Base socket class for sending and listening messages. More...

#include <SpecialSocketBase.hpp>

Collaboration diagram for srs::connection::SpecialSocket:

Public Member Functions

void register_send_action (this auto &&self, asio::awaitable< void > action, const std::shared_ptr< typename std::remove_cvref_t< decltype(self)>::ConnectionType > &connection)
 Registering the send action.
void listen (this auto &self, io_context_type &io_context)
 Listen to any UDP data.
auto cancel_listen_after (this auto &&self, io_context_type &io_context, std::chrono::seconds waiting_time=std::chrono::seconds(2)) -> std::future< void >
 Cancelling the listening action after a certain time.
auto wait_for_listen_finish (std::chrono::seconds time) -> std::optional< std::future_status >
 Blocking the current thread by waiting the listen action to finish until a certain time duration.
void set_report (AppReport *report)
void before_socket_close ()
auto get_socket () const -> udp::socket &
 Getter for the asio udp socket object.
auto get_port () const -> int
 Getter for the port number.
auto get_future () -> auto &
 Getter for the status of the listen action.
auto get_n_records () const -> std::size_t
 Getter for the number of frames read.
auto get_n_bytes () const -> std::size_t
 Getter for the number of bytes read.
auto get_total_time_ns () const -> std::uint64_t
 Getter for the total listening time in nano seconds.
auto get_report () -> auto *

Static Public Member Functions

template<SpecialSocketDerived SocketType, typename... Args>
static auto create (int port_number, io_context_type &io_context, Args &&... args) -> std::expected< std::shared_ptr< SocketType >, std::error_code >

Protected Member Functions

 SpecialSocket (int port_number, io_context_type &io_context)
 Projected constructor, which can only be called from the derived classes.
auto get_cancel_timer () -> auto &

Private Member Functions

auto cancel_coroutine () -> asio::awaitable< void >
auto bind_socket () -> std::error_code
auto close_socket () -> std::error_code

Static Private Member Functions

template<SpecialSocketDerived SocketType>
static auto async_listen_all_connections (std::shared_ptr< SocketType > socket) -> asio::awaitable< void >

Private Attributes

int port_number_ = 0
AppReport * report_ = nullptr
std::unique_ptr< udp::socket > socket_
std::shared_future< std::variant< std::monostate, std::monostate > > listen_future_
asio::system_timer cancel_timer_
 Used for cancel the unfinished coroutine.
std::chrono::steady_clock clock_
std::chrono::time_point< std::chrono::steady_clock, std::chrono::nanoseconds > time_point_
std::size_t n_records_ = 0
std::size_t n_bytes = 0
std::uint64_t total_time_ns_ = 0

Detailed Description

Base socket class for sending and listening messages.

Definition at line 58 of file SpecialSocketBase.hpp.

Constructor & Destructor Documentation

◆ SpecialSocket()

srs::connection::SpecialSocket::SpecialSocket ( int port_number,
io_context_type & io_context )
explicitprotected

Projected constructor, which can only be called from the derived classes.

Parameters
port_numerPort number binding to the socket for the listening action.
io_contextasio io context.

Definition at line 18 of file SpecialSocketBase.cpp.

Member Function Documentation

◆ async_listen_all_connections()

template<SpecialSocketDerived SocketType>
auto srs::connection::SpecialSocket::async_listen_all_connections ( std::shared_ptr< SocketType > socket) -> asio::awaitable< void >
staticprivate

Definition at line 208 of file SpecialSocketBase.hpp.

◆ before_socket_close()

void srs::connection::SpecialSocket::before_socket_close ( )
inline

Definition at line 108 of file SpecialSocketBase.hpp.

◆ bind_socket()

auto srs::connection::SpecialSocket::bind_socket ( ) -> std::error_code
private

Definition at line 35 of file SpecialSocketBase.cpp.

◆ cancel_coroutine()

auto srs::connection::SpecialSocket::cancel_coroutine ( ) -> asio::awaitable< void >
private

Definition at line 27 of file SpecialSocketBase.cpp.

◆ cancel_listen_after()

auto srs::connection::SpecialSocket::cancel_listen_after ( this auto && self,
io_context_type & io_context,
std::chrono::seconds waiting_time = std::chrono::seconds(2) ) -> std::future< void >

Cancelling the listening action after a certain time.

Parameters
selfDeduce this self reference
io_contextReference to the io_context
waiting_timeTime until the listen action is cancelled.
Returns
a future object to check whether the listen action is cancelled.

Definition at line 273 of file SpecialSocketBase.hpp.

◆ close_socket()

auto srs::connection::SpecialSocket::close_socket ( ) -> std::error_code
private

Definition at line 44 of file SpecialSocketBase.cpp.

◆ create()

template<SpecialSocketDerived SocketType, typename... Args>
auto srs::connection::SpecialSocket::create ( int port_number,
io_context_type & io_context,
Args &&... args ) -> std::expected< std::shared_ptr< SocketType >, std::error_code >
static

Definition at line 190 of file SpecialSocketBase.hpp.

◆ get_cancel_timer()

auto srs::connection::SpecialSocket::get_cancel_timer ( ) -> auto &
inlineprotected

Definition at line 164 of file SpecialSocketBase.hpp.

◆ get_future()

auto srs::connection::SpecialSocket::get_future ( ) -> auto &
inline

Getter for the status of the listen action.

Returns
The future status of the listen action coroutine.

Definition at line 131 of file SpecialSocketBase.hpp.

◆ get_n_bytes()

auto srs::connection::SpecialSocket::get_n_bytes ( ) const -> std::size_t
inline

Getter for the number of bytes read.

Returns
Number of bytes read.

Definition at line 145 of file SpecialSocketBase.hpp.

◆ get_n_records()

auto srs::connection::SpecialSocket::get_n_records ( ) const -> std::size_t
inline

Getter for the number of frames read.

Returns
Number of frames read.

Definition at line 138 of file SpecialSocketBase.hpp.

◆ get_port()

auto srs::connection::SpecialSocket::get_port ( ) const -> int
inlinenodiscard

Getter for the port number.

Returns
Port number.

Definition at line 124 of file SpecialSocketBase.hpp.

◆ get_report()

auto srs::connection::SpecialSocket::get_report ( ) -> auto *
inline

Definition at line 154 of file SpecialSocketBase.hpp.

◆ get_socket()

auto srs::connection::SpecialSocket::get_socket ( ) const -> udp::socket &
inlinenodiscard

Getter for the asio udp socket object.

Returns
shared pointer to the udp socket.

Definition at line 117 of file SpecialSocketBase.hpp.

◆ get_total_time_ns()

auto srs::connection::SpecialSocket::get_total_time_ns ( ) const -> std::uint64_t
inline

Getter for the total listening time in nano seconds.

Returns
Total listening time.

Definition at line 152 of file SpecialSocketBase.hpp.

◆ listen()

void srs::connection::SpecialSocket::listen ( this auto & self,
io_context_type & io_context )

Listen to any UDP data.

Parameters
selfDeduce this self reference
io_contextReference to the io_context

Definition at line 263 of file SpecialSocketBase.hpp.

◆ register_send_action()

void srs::connection::SpecialSocket::register_send_action ( this auto && self,
asio::awaitable< void > action,
const std::shared_ptr< typename std::remove_cvref_t< decltype(self)>::ConnectionType > & connection )

Registering the send action.

Invoke an action corresponding the type of connection specified in the socket class. The connection type should all derive from srs::connection::ConnectionBase class.

Parameters
selfDeduce this self reference
actionAn asio::awaitable action object.
connectionA connection shared pointer.

Definition at line 249 of file SpecialSocketBase.hpp.

◆ set_report()

void srs::connection::SpecialSocket::set_report ( AppReport * report)
inline

Definition at line 107 of file SpecialSocketBase.hpp.

◆ wait_for_listen_finish()

auto srs::connection::SpecialSocket::wait_for_listen_finish ( std::chrono::seconds time) -> std::optional< std::future_status >

Blocking the current thread by waiting the listen action to finish until a certain time duration.

Parameters
timeTime to wait for the listen action to finish.
Returns
The result of waiting.

Definition at line 51 of file SpecialSocketBase.cpp.

Member Data Documentation

◆ cancel_timer_

asio::system_timer srs::connection::SpecialSocket::cancel_timer_
private

Used for cancel the unfinished coroutine.

Definition at line 171 of file SpecialSocketBase.hpp.

◆ clock_

std::chrono::steady_clock srs::connection::SpecialSocket::clock_
private

Definition at line 174 of file SpecialSocketBase.hpp.

◆ listen_future_

std::shared_future<std::variant<std::monostate, std::monostate> > srs::connection::SpecialSocket::listen_future_
private

Definition at line 170 of file SpecialSocketBase.hpp.

◆ n_bytes

std::size_t srs::connection::SpecialSocket::n_bytes = 0
private

Definition at line 177 of file SpecialSocketBase.hpp.

◆ n_records_

std::size_t srs::connection::SpecialSocket::n_records_ = 0
private

Definition at line 176 of file SpecialSocketBase.hpp.

◆ port_number_

int srs::connection::SpecialSocket::port_number_ = 0
private

Definition at line 167 of file SpecialSocketBase.hpp.

◆ report_

AppReport* srs::connection::SpecialSocket::report_ = nullptr
private

Definition at line 168 of file SpecialSocketBase.hpp.

◆ socket_

std::unique_ptr<udp::socket> srs::connection::SpecialSocket::socket_
private

Definition at line 169 of file SpecialSocketBase.hpp.

◆ time_point_

std::chrono::time_point<std::chrono::steady_clock, std::chrono::nanoseconds> srs::connection::SpecialSocket::time_point_
private

Definition at line 175 of file SpecialSocketBase.hpp.

◆ total_time_ns_

std::uint64_t srs::connection::SpecialSocket::total_time_ns_ = 0
private

Definition at line 178 of file SpecialSocketBase.hpp.


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