10Duke Scale C++ Client
Loading...
Searching...
No Matches
tenduke::test::fakes::FakeSocket Class Reference
Inheritance diagram for tenduke::test::fakes::FakeSocket:
tenduke::osa::Socket

Public Member Functions

std::unique_ptr< Socket > accept (uint32_t timeoutMs) override
 Accepts next connection from listening socket, with a timeout.
 
std::unique_ptr< Socket > accept () override
 Accepts next connection from listening socket.
 
void listen () override
 Configures the socket to listen for incoming connections.
 
int read (void *buffer, std::size_t bufferSize) override
 Reads bytes from the socket.
 
int write (const void *buffer, std::size_t len) override
 Write bytes to the socket.
 
std::uint16_t getPort () const override
 Returns port of the socket.
 
void setNonBlocking () override
 Sets the socket to non-blocking mode.
 

Public Attributes

std::uint16_t port
 
std::atomic_bool acceptReady
 
std::deque< tenduke::osa::Socket * > acceptedSockets
 
std::vector< std::string > writtenData
 
std::string readData
 

Member Function Documentation

◆ accept() [1/2]

std::unique_ptr<::Socket > tenduke::test::fakes::FakeSocket::accept ( )
overridevirtual

Accepts next connection from listening socket.

No timeout.

Returns
the child socket

Implements tenduke::osa::Socket.

◆ accept() [2/2]

std::unique_ptr<::Socket > tenduke::test::fakes::FakeSocket::accept ( uint32_t  timeoutMs)
overridevirtual

Accepts next connection from listening socket, with a timeout.

The socket must be set to listening mode using listen() before calling this method. New connection is returned as new tenduke::osa::Socket. This method times out after timeoutMs milliseconds and then returns nullptr.

IMPORTANT NOTE: When using timeout, you should call setNonBlocking() on the socket to avoid race conditions.

Parameters
timeoutMstimeout in milliseconds. Zero timeout is not yet supported.
Returns
the child socket or nullptr if accept timed out
Exceptions
tenduke::net::NetworkingExceptionin any case of error

Implements tenduke::osa::Socket.

◆ getPort()

uint16_t tenduke::test::fakes::FakeSocket::getPort ( ) const
overridevirtual

Returns port of the socket.

Returns
the port number

Implements tenduke::osa::Socket.

◆ listen()

void tenduke::test::fakes::FakeSocket::listen ( )
overridevirtual

Configures the socket to listen for incoming connections.

Exceptions
tenduke::net::NetworkingExceptionin any case of error

Implements tenduke::osa::Socket.

◆ read()

int tenduke::test::fakes::FakeSocket::read ( void *  buffer,
std::size_t  bufferSize 
)
overridevirtual

Reads bytes from the socket.

Parameters
bufferbuffer where the bytes are placed to
bufferSizesize of the buffer in bytes
Returns
number of bytes read. Returns -1, if socket is non-blocking and nothing to read yet.
Exceptions
tenduke::net::NetworkingExceptionin any case of error

Implements tenduke::osa::Socket.

◆ setNonBlocking()

void tenduke::test::fakes::FakeSocket::setNonBlocking ( )
overridevirtual

Sets the socket to non-blocking mode.

Exceptions
tenduke::net::NetworkingExceptionin any case of error

Implements tenduke::osa::Socket.

◆ write()

int tenduke::test::fakes::FakeSocket::write ( const void *  buffer,
std::size_t  len 
)
overridevirtual

Write bytes to the socket.

Parameters
bufferthese bytes are written
lennumber of bytes to write
Returns
number of bytes written
Exceptions
tenduke::net::NetworkingExceptionin any case of error

Implements tenduke::osa::Socket.


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