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

Class used to test the unix asynchronous stream socket API. More...

Inheritance diagram for TcpAsyncSocket:
Collaboration diagram for TcpAsyncSocket:

Protected Member Functions

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

Static Protected Member Functions

static Tcp::AsyncSocket & peer ()
 get the socket accepted by the echo server.
 
static void onEchoRead (const std::error_code &ec, const char *data, size_t size, bool more)
 receive the data to send back.
 
static void onEchoWrite (const std::error_code &ec, size_t size)
 send back the data received by the echo server.
 
static void onEchoAccept (Tcp::Socket &&sock, const std::error_code &ec, bool more)
 adopt the socket accepted by the echo server.
 
static void onWrite (const std::error_code &ec, size_t size)
 handler resubmitting a write from within itself.
 
static void onConnect (const std::error_code &ec)
 handler retrying the connection from within itself.
 
static void onRead (const std::error_code &ec, const char *data, size_t size, bool more)
 handler resubmitting a read from within itself.
 
static void onReportMulti (const std::error_code &ec, const char *data, size_t size, bool more)
 report a multishot completion to the test thread.
 
static void onReportWait (const std::error_code &ec, bool more)
 report a wait completion to the test thread.
 

Protected Attributes

Tcp::AsyncAcceptor _server
 echo server.
 

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 bool _more = false
 last reported multishot state.
 
static char _echobuf [1024] = {}
 buffer used by the echo server.
 
static Tcp::AsyncSocket * _current = nullptr
 socket used by the resubmitting handler.
 
static int _rearms = 0
 number of resubmissions left to perform from the read handler.
 
static const IpAddress _host = "::1"
 host.
 
static const IpAddress _blackhole = "192.0.2.1"
 unreachable host keeping a connection attempt pending.
 
static const uint16_t _port = 5034
 port.
 
static const uint16_t _stallport = 5035
 
static const std::chrono::milliseconds _timeout {1000}
 timeout.
 

Detailed Description

Class used to test the unix asynchronous stream socket API.

Member Function Documentation

◆ onConnect()

static void TcpAsyncSocket::onConnect ( const std::error_code & ec)
inlinestaticprotected

handler retrying the connection from within itself.

Parameters
ecerror reported by the socket.

◆ onEchoAccept()

static void TcpAsyncSocket::onEchoAccept ( Tcp::Socket && sock,
const std::error_code & ec,
bool more )
inlinestaticprotected

adopt the socket accepted by the echo server.

Parameters
sockaccepted socket.
ecerror reported by the acceptor.
moretrue if the acceptation stays armed.

◆ onEchoRead()

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

receive the data to send back.

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

◆ onEchoWrite()

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

send back the data received by the echo server.

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

◆ onRead()

static void TcpAsyncSocket::onRead ( const std::error_code & ec,
const char * data,
size_t size,
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.
moretrue if the read stays armed.

◆ onReportMulti()

static void TcpAsyncSocket::onReportMulti ( const std::error_code & ec,
const char * data,
size_t size,
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.
moretrue if the read stays armed.

◆ onReportWait()

static void TcpAsyncSocket::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 TcpAsyncSocket::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.

◆ peer()

static Tcp::AsyncSocket & TcpAsyncSocket::peer ( )
inlinestaticprotected

get the socket accepted by the echo server.

Returns
the socket accepted by the echo server.

◆ SetUp()

void TcpAsyncSocket::SetUp ( )
inlineoverrideprotected

Sets up the test fixture.

◆ TearDown()

void TcpAsyncSocket::TearDown ( )
inlineoverrideprotected

Tears down the test fixture.

Member Data Documentation

◆ _blackhole

const IpAddress TcpAsyncSocket::_blackhole = "192.0.2.1"
staticprotected

unreachable host keeping a connection attempt pending.

◆ _buf

char TcpAsyncSocket::_buf = {}
staticprotected

read buffer.

◆ _code

std::error_code TcpAsyncSocket::_code
staticprotected

last reported error.

◆ _completions

int TcpAsyncSocket::_completions = 0
staticprotected

number of completions reported.

◆ _cond

Condition TcpAsyncSocket::_cond
staticprotected

condition variable.

◆ _current

Tcp::AsyncSocket * TcpAsyncSocket::_current = nullptr
staticprotected

socket used by the resubmitting handler.

◆ _echobuf

char TcpAsyncSocket::_echobuf = {}
staticprotected

buffer used by the echo server.

◆ _host

const IpAddress TcpAsyncSocket::_host = "::1"
staticprotected

host.

◆ _more

bool TcpAsyncSocket::_more = false
staticprotected

last reported multishot state.

◆ _mut

Mutex TcpAsyncSocket::_mut
staticprotected

condition mutex.

◆ _port

const uint16_t TcpAsyncSocket::_port = 5034
staticprotected

port.

◆ _rearms

int TcpAsyncSocket::_rearms = 0
staticprotected

number of resubmissions left to perform from the read handler.

◆ _server

Tcp::AsyncAcceptor TcpAsyncSocket::_server
protected

echo server.

◆ _stallport

const uint16_t TcpAsyncSocket::_stallport = 5035
staticprotected

◆ _timeout

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

timeout.

◆ _transferred

size_t TcpAsyncSocket::_transferred = 0
staticprotected

number of bytes reported by the last completion.


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