join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
UdpAsyncSocket Class Reference

Class used to test the udp asynchronous datagram socket API. More...

Inheritance diagram for UdpAsyncSocket:
Collaboration diagram for UdpAsyncSocket:

Protected Member Functions

void SetUp () override
 Sets up the test fixture.
 
void TearDown () override
 Tears down the test fixture.
 

Static Protected Member Functions

static Udp::AsyncSocket & server ()
 get the echo server socket.
 
static void onEchoRead (const std::error_code &ec, const char *data, size_t size, const Udp::Endpoint &from, bool more)
 send back the datagram received by the echo server.
 
static void onEchoWrite (const std::error_code &ec, size_t size)
 wait for the next datagram to echo.
 
static void onReport (const std::error_code &ec, size_t size)
 report a completion to the test thread.
 
static void onReportRead (const std::error_code &ec, const char *data, size_t size, bool more)
 report a read completion to the test thread.
 
static void onReportFrom (const std::error_code &ec, const char *data, size_t size, const Udp::Endpoint &from, bool more)
 report a read completion and the endpoint it came from to the test thread.
 
static void onReportMulti (const std::error_code &ec, const char *data, size_t size, const Udp::Endpoint &from, bool more)
 report a multishot completion to the test thread.
 
static void onRead (const std::error_code &ec, const char *data, size_t size, const Udp::Endpoint &from, bool more)
 handler resubmitting a read from within itself.
 
static void onWrite (const std::error_code &ec, size_t size)
 handler resubmitting a write from within itself.
 
static Udp::AsyncSocket & moved ()
 get the socket receiving the move performed from a handler.
 
static void onReadAndMove (const std::error_code &ec, const char *data, size_t size, const Udp::Endpoint &from, bool more)
 handler moving the socket from within itself.
 
static void onWriteAndClose (const std::error_code &ec, size_t size)
 handler closing the socket from within itself.
 
static void onReportWait (const std::error_code &ec, bool more)
 report a wait completion to the test thread.
 

Static Protected Attributes

static Mutex _mut
 condition mutex.
 
static Condition _cond
 condition variable.
 
static std::error_code _code
 last reported error.
 
static int _completions = 0
 number of completions reported.
 
static size_t _transferred = 0
 number of bytes reported by the last completion.
 
static char _buf [1024] = {}
 read buffer.
 
static Udp::Endpoint _from
 endpoint the last datagram was received from.
 
static bool _more = false
 last reported multishot state.
 
static char _echobuf [1024] = {}
 buffer used by the echo server.
 
static Udp::Endpoint _echofrom
 endpoint the echo server received the last datagram from.
 
static Udp::AsyncSocket * _current = nullptr
 socket used by the resubmitting handler.
 
static int _rearms = 0
 number of resubmissions left to perform from a handler.
 
static Udp::Endpoint _dest
 destination used by the resubmitting write handler.
 
static const std::string _host = "127.0.0.1"
 host.
 
static const uint16_t _port = 5036
 port.
 
static const std::chrono::milliseconds _timeout {1000}
 timeout.
 

Detailed Description

Class used to test the udp asynchronous datagram socket API.

Member Function Documentation

◆ moved()

static Udp::AsyncSocket & UdpAsyncSocket::moved ( )
inlinestaticprotected

get the socket receiving the move performed from a handler.

Returns
the socket receiving the move performed from a handler.

◆ onEchoRead()

static void UdpAsyncSocket::onEchoRead ( const std::error_code & ec,
const char * data,
size_t size,
const Udp::Endpoint & from,
bool more )
inlinestaticprotected

send back the datagram received by the echo server.

Parameters
ecerror reported by the socket.
databuffer holding the data received.
sizenumber of bytes read.
fromendpoint the datagram was received from.
moretrue if the read stays armed.

◆ onEchoWrite()

static void UdpAsyncSocket::onEchoWrite ( const std::error_code & ec,
size_t size )
inlinestaticprotected

wait for the next datagram to echo.

Parameters
ecerror reported by the socket.
sizenumber of bytes written.

◆ onRead()

static void UdpAsyncSocket::onRead ( const std::error_code & ec,
const char * data,
size_t size,
const Udp::Endpoint & from,
bool more )
inlinestaticprotected

handler resubmitting a read from within itself.

Parameters
ecerror reported by the socket.
databuffer holding the data received.
sizenumber of bytes read.
fromendpoint the datagram was received from.
moretrue if the read stays armed.

◆ onReadAndMove()

static void UdpAsyncSocket::onReadAndMove ( const std::error_code & ec,
const char * data,
size_t size,
const Udp::Endpoint & from,
bool more )
inlinestaticprotected

handler moving the socket from within itself.

Parameters
ecerror reported by the socket.
databuffer holding the data received.
sizenumber of bytes read.
fromendpoint the datagram was received from.
moretrue if the read stays armed.

◆ onReport()

static void UdpAsyncSocket::onReport ( const std::error_code & ec,
size_t size )
inlinestaticprotected

report a completion to the test thread.

Parameters
ecerror reported by the socket.
sizenumber of bytes transferred.

◆ onReportFrom()

static void UdpAsyncSocket::onReportFrom ( const std::error_code & ec,
const char * data,
size_t size,
const Udp::Endpoint & from,
bool more )
inlinestaticprotected

report a read completion and the endpoint it came from to the test thread.

Parameters
ecerror reported by the socket.
databuffer holding the data received.
sizenumber of bytes read.
fromendpoint the datagram was received from.
moretrue if the read stays armed.

◆ onReportMulti()

static void UdpAsyncSocket::onReportMulti ( const std::error_code & ec,
const char * data,
size_t size,
const Udp::Endpoint & from,
bool more )
inlinestaticprotected

report a multishot completion to the test thread.

Parameters
ecerror reported by the socket.
databuffer holding the data received.
sizenumber of bytes read.
fromendpoint the datagram was received from.
moretrue if the read stays armed.

◆ onReportRead()

static void UdpAsyncSocket::onReportRead ( const std::error_code & ec,
const char * data,
size_t size,
bool more )
inlinestaticprotected

report a read completion to the test thread.

Parameters
ecerror reported by the socket.
databuffer holding the data received.
sizenumber of bytes read.
moretrue if the read stays armed.

◆ onReportWait()

static void UdpAsyncSocket::onReportWait ( const std::error_code & ec,
bool more )
inlinestaticprotected

report a wait completion to the test thread.

Parameters
ecerror reported by the socket.
moretrue if the wait stays armed.

◆ onWrite()

static void UdpAsyncSocket::onWrite ( const std::error_code & ec,
size_t size )
inlinestaticprotected

handler resubmitting a write from within itself.

Parameters
ecerror reported by the socket.
sizenumber of bytes written.

◆ onWriteAndClose()

static void UdpAsyncSocket::onWriteAndClose ( const std::error_code & ec,
size_t size )
inlinestaticprotected

handler closing the socket from within itself.

Parameters
ecerror reported by the socket.
sizenumber of bytes written.

◆ server()

static Udp::AsyncSocket & UdpAsyncSocket::server ( )
inlinestaticprotected

get the echo server socket.

Returns
the echo server socket.

◆ SetUp()

void UdpAsyncSocket::SetUp ( )
inlineoverrideprotected

Sets up the test fixture.

◆ TearDown()

void UdpAsyncSocket::TearDown ( )
inlineoverrideprotected

Tears down the test fixture.

Member Data Documentation

◆ _buf

char UdpAsyncSocket::_buf = {}
staticprotected

read buffer.

◆ _code

std::error_code UdpAsyncSocket::_code
staticprotected

last reported error.

◆ _completions

int UdpAsyncSocket::_completions = 0
staticprotected

number of completions reported.

◆ _cond

Condition UdpAsyncSocket::_cond
staticprotected

condition variable.

◆ _current

Udp::AsyncSocket * UdpAsyncSocket::_current = nullptr
staticprotected

socket used by the resubmitting handler.

◆ _dest

Udp::Endpoint UdpAsyncSocket::_dest
staticprotected

destination used by the resubmitting write handler.

◆ _echobuf

char UdpAsyncSocket::_echobuf = {}
staticprotected

buffer used by the echo server.

◆ _echofrom

Udp::Endpoint UdpAsyncSocket::_echofrom
staticprotected

endpoint the echo server received the last datagram from.

◆ _from

Udp::Endpoint UdpAsyncSocket::_from
staticprotected

endpoint the last datagram was received from.

◆ _host

const std::string UdpAsyncSocket::_host = "127.0.0.1"
staticprotected

host.

◆ _more

bool UdpAsyncSocket::_more = false
staticprotected

last reported multishot state.

◆ _mut

Mutex UdpAsyncSocket::_mut
staticprotected

condition mutex.

◆ _port

const uint16_t UdpAsyncSocket::_port = 5036
staticprotected

port.

◆ _rearms

int UdpAsyncSocket::_rearms = 0
staticprotected

number of resubmissions left to perform from a handler.

◆ _timeout

const std::chrono::milliseconds UdpAsyncSocket::_timeout {1000}
staticprotected

timeout.

◆ _transferred

size_t UdpAsyncSocket::_transferred = 0
staticprotected

number of bytes reported by the last completion.


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