10Duke Enterprise C++ SDK
Loading...
Searching...
No Matches
AbstractBaseSocket< DESCRIPTOR_TYPE > Class Template Referenceabstract

#include <AbstractBaseSocket.h>

Detailed Description

template<typename DESCRIPTOR_TYPE>
class AbstractBaseSocket< DESCRIPTOR_TYPE >

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

Inheritance diagram for AbstractBaseSocket< DESCRIPTOR_TYPE >:
tenduke::osa::Socket

Public Member Functions

 AbstractBaseSocket (const AbstractBaseSocket &)=delete
 
 AbstractBaseSocket (const DESCRIPTOR_TYPE descriptor)
 Constructs a new socket.
 
AbstractBaseSocketoperator= (const AbstractBaseSocket &)=delete
 
std::unique_ptr<::tenduke::osa::Socketaccept (const 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

 
virtual std::unique_ptr< Socketaccept ()=0
 Accepts next connection from listening socket.
 
void listen () override
 Configures the socket to listen for incoming connections.
Exceptions
tenduke::net::NetworkingExceptionin any case of error

 
int read (void *buffer, const 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, const 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 void bind (std::uint32_t ipAddress, std::uint16_t port)=0
 Binds the 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

virtual bool hasIncomingConnections (std::uint32_t timeoutMs) const=0
 Checks if the socket has incoming connections.
 
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.
 

Static Protected Member Functions

static struct::timeval timeFromMilliseconds (const std::uint32_t milliseconds)
 Returns struct timeval populated from milliseconds.
 

Protected Attributes

DESCRIPTOR_TYPE descriptor
 The socket descriptor.
 

Member Function Documentation

◆ accept() [1/2]

template<typename DESCRIPTOR_TYPE>
virtual std::unique_ptr< Socket > tenduke::osa::Socket::accept ( )
virtual

Accepts next connection from listening socket.

No timeout.

Returns
the child socket

Implements tenduke::osa::Socket.

◆ accept() [2/2]

template<typename DESCRIPTOR_TYPE>
std::unique_ptr<::tenduke::osa::Socket > tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >::accept ( const uint32_t timeoutMs)
inlineoverridevirtual

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.

◆ getLastError()

template<typename DESCRIPTOR_TYPE>
virtual int tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >::getLastError ( ) const
protectedpure virtual

Returns last error code.

Returns
-

◆ hasIncomingConnections()

template<typename DESCRIPTOR_TYPE>
virtual bool tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >::hasIncomingConnections ( std::uint32_t timeoutMs) const
protectedpure virtual

Checks if the socket has incoming connections.

The check will wait for incoming connections for the specified timeout.

Parameters
timeoutMstimeout in milliseconds
Returns
true if there are incoming connections, false otherwise
Exceptions
tenduke::net::NetworkingExceptionif the check failed

◆ listen()

template<typename DESCRIPTOR_TYPE>
void tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >::listen ( )
inlineoverridevirtual

Configures the socket to listen for incoming connections.

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

Implements tenduke::osa::Socket.

◆ mkErrorMessage() [1/3]

template<typename DESCRIPTOR_TYPE>
virtual std::string tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >::mkErrorMessage ( const char * body) const
inlineprotectedvirtual

Builds error message.

Parameters
body-
Returns
-

◆ mkErrorMessage() [2/3]

template<typename DESCRIPTOR_TYPE>
virtual std::string tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >::mkErrorMessage ( const std::string & body) const
inlineprotectedvirtual

Builds error message.

Parameters
body-
Returns
-

◆ mkErrorMessage() [3/3]

template<typename DESCRIPTOR_TYPE>
virtual std::string tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >::mkErrorMessage ( const std::string & body,
int errorCode ) const
protectedpure virtual

Builds error message.

Parameters
body-
errorCode-
Returns
-

◆ read()

template<typename DESCRIPTOR_TYPE>
int tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >::read ( void * buffer,
const std::size_t bufferSize )
inlineoverridevirtual

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.

◆ timeFromMilliseconds()

template<typename DESCRIPTOR_TYPE>
static struct::timeval tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >::timeFromMilliseconds ( const std::uint32_t milliseconds)
inlinestaticprotected

Returns struct timeval populated from milliseconds.

Parameters
milliseconds-
Returns
-

◆ wouldBlock()

template<typename DESCRIPTOR_TYPE>
virtual bool tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >::wouldBlock ( int errorCode) const
protectedpure virtual

Checks if error code means that call would have blocked.

Parameters
errorCode-
Returns
-

◆ write()

template<typename DESCRIPTOR_TYPE>
int tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >::write ( const void * buffer,
const std::size_t len )
inlineoverridevirtual

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 file: