10Duke Scale C++ Client
Loading...
Searching...
No Matches
tenduke::osa::AbstractBaseSocket Class Referenceabstract

#include <AbstractBaseSocket.h>

Detailed Description

Abstract base implementation of tenduke::osa::Socket.

Inheritance diagram for tenduke::osa::AbstractBaseSocket:
tenduke::osa::Socket

Public Member Functions

 AbstractBaseSocket (uint32_t address, uint16_t port)
 Constructs new socket.
 
std::unique_ptr< tenduke::osa::Socketaccept (uint32_t timeoutMs) override
 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

 
void listen () override
 Configures the socket to listen for incoming connections.
Exceptions
tenduke::net::NetworkingExceptionin any case of error

 
int read (void *buffer, std::size_t bufferSize) override
 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

 
int write (const void *buffer, std::size_t len) override
 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

 
- Public Member Functions inherited from tenduke::osa::Socket
virtual std::unique_ptr< Socketaccept ()=0
 Accepts next connection from listening socket.
 
virtual std::uint16_t getPort () const =0
 Returns port of the socket.
 
virtual void setNonBlocking ()=0
 Sets the socket to non-blocking mode.
 

Protected Member Functions

 AbstractBaseSocket (int descriptor, const struct ::sockaddr_in *address)
 Constructs new instance.
 
virtual std::unique_ptr< tenduke::osa::SocketcreateSocket (int descriptor, const struct ::sockaddr_in *address)=0
 Creates a socket.
 
virtual int getLastError () const =0
 Returns last error code.
 
virtual std::string mkErrorMessage (const std::string &body) const
 Builds error message.
 
virtual std::string mkErrorMessage (const char *body) const
 Builds error message.
 
virtual std::string mkErrorMessage (const std::string &body, int errorCode) const =0
 Builds error message.
 
virtual bool wouldBlock (int errorCode) const =0
 Checks if error code means that call would have blocked.
 

Protected Attributes

SocketDescriptor descriptor
 The socket descriptor.
 

Constructor & Destructor Documentation

◆ AbstractBaseSocket() [1/2]

tenduke::osa::AbstractBaseSocket::AbstractBaseSocket ( uint32_t  address,
uint16_t  port 
)

Constructs new socket.

Parameters
addressaddress of the socket
portport, 0 indicates random port.

◆ AbstractBaseSocket() [2/2]

tenduke::osa::AbstractBaseSocket::AbstractBaseSocket ( int  descriptor,
const struct ::sockaddr_in *  address 
)
protected

Constructs new instance.

Parameters
descriptor-
address-

Member Function Documentation

◆ accept()

std::unique_ptr< xdosa::Socket > tenduke::osa::AbstractBaseSocket::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.

◆ createSocket()

virtual std::unique_ptr< tenduke::osa::Socket > tenduke::osa::AbstractBaseSocket::createSocket ( int  descriptor,
const struct ::sockaddr_in *  address 
)
protectedpure virtual

Creates a socket.

Parameters
descriptor-
address-
Returns
-

◆ getLastError()

virtual int tenduke::osa::AbstractBaseSocket::getLastError ( ) const
protectedpure virtual

Returns last error code.

Returns
-

◆ listen()

void tenduke::osa::AbstractBaseSocket::listen ( )
overridevirtual

Configures the socket to listen for incoming connections.

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

Implements tenduke::osa::Socket.

◆ mkErrorMessage() [1/3]

std::string tenduke::osa::AbstractBaseSocket::mkErrorMessage ( const char *  body) const
protectedvirtual

Builds error message.

Parameters
body-
Returns
-

◆ mkErrorMessage() [2/3]

std::string tenduke::osa::AbstractBaseSocket::mkErrorMessage ( const std::string &  body) const
protectedvirtual

Builds error message.

Parameters
body-
Returns
-

◆ mkErrorMessage() [3/3]

virtual std::string tenduke::osa::AbstractBaseSocket::mkErrorMessage ( const std::string &  body,
int  errorCode 
) const
protectedpure virtual

Builds error message.

Parameters
body-
errorCode-
Returns
-

◆ read()

int tenduke::osa::AbstractBaseSocket::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.

◆ wouldBlock()

virtual bool tenduke::osa::AbstractBaseSocket::wouldBlock ( int  errorCode) const
protectedpure virtual

Checks if error code means that call would have blocked.

Parameters
errorCode-
Returns
-

◆ write()

int tenduke::osa::AbstractBaseSocket::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: