#include <AbstractBaseSocket.h>
Abstract base implementation of tenduke::osa::Socket.
|
| AbstractBaseSocket (uint32_t address, uint16_t port) |
| Constructs new socket.
|
|
std::unique_ptr< tenduke::osa::Socket > | accept (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
-
timeoutMs | timeout in milliseconds. Zero timeout is not yet supported. |
- Returns
- the child socket or
nullptr if accept timed out
- Exceptions
-
|
|
void | listen () override |
| Configures the socket to listen for incoming connections.- Exceptions
-
|
|
int | read (void *buffer, std::size_t bufferSize) override |
| Reads bytes from the socket.- Parameters
-
buffer | buffer where the bytes are placed to |
bufferSize | size of the buffer in bytes |
- Returns
- number of bytes read. Returns -1, if socket is non-blocking and nothing to read yet.
- Exceptions
-
|
|
int | write (const void *buffer, std::size_t len) override |
| Write bytes to the socket.- Parameters
-
buffer | these bytes are written |
len | number of bytes to write |
- Returns
- number of bytes written
- Exceptions
-
|
|
virtual std::unique_ptr< Socket > | accept ()=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.
|
|
|
| AbstractBaseSocket (int descriptor, const struct ::sockaddr_in *address) |
| Constructs new instance.
|
|
virtual std::unique_ptr< tenduke::osa::Socket > | createSocket (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.
|
|
◆ AbstractBaseSocket() [1/2]
tenduke::osa::AbstractBaseSocket::AbstractBaseSocket |
( |
uint32_t |
address, |
|
|
uint16_t |
port |
|
) |
| |
Constructs new socket.
- Parameters
-
address | address of the socket |
port | port, 0 indicates random port. |
◆ AbstractBaseSocket() [2/2]
tenduke::osa::AbstractBaseSocket::AbstractBaseSocket |
( |
int |
descriptor, |
|
|
const struct ::sockaddr_in * |
address |
|
) |
| |
|
protected |
Constructs new instance.
- Parameters
-
◆ 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
-
timeoutMs | timeout in milliseconds. Zero timeout is not yet supported. |
- Returns
- the child socket or
nullptr
if accept timed out
- Exceptions
-
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
-
- 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
-
Implements tenduke::osa::Socket.
◆ mkErrorMessage() [1/3]
std::string tenduke::osa::AbstractBaseSocket::mkErrorMessage |
( |
const char * |
body | ) |
const |
|
protectedvirtual |
Builds error message.
- Parameters
-
- Returns
- -
◆ mkErrorMessage() [2/3]
std::string tenduke::osa::AbstractBaseSocket::mkErrorMessage |
( |
const std::string & |
body | ) |
const |
|
protectedvirtual |
Builds error message.
- Parameters
-
- Returns
- -
◆ mkErrorMessage() [3/3]
virtual std::string tenduke::osa::AbstractBaseSocket::mkErrorMessage |
( |
const std::string & |
body, |
|
|
int |
errorCode |
|
) |
| const |
|
protectedpure virtual |
Builds error message.
- Parameters
-
- Returns
- -
◆ read()
int tenduke::osa::AbstractBaseSocket::read |
( |
void * |
buffer, |
|
|
std::size_t |
bufferSize |
|
) |
| |
|
overridevirtual |
Reads bytes from the socket.
- Parameters
-
buffer | buffer where the bytes are placed to |
bufferSize | size of the buffer in bytes |
- Returns
- number of bytes read. Returns -1, if socket is non-blocking and nothing to read yet.
- Exceptions
-
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
-
- Returns
- -
◆ write()
int tenduke::osa::AbstractBaseSocket::write |
( |
const void * |
buffer, |
|
|
std::size_t |
len |
|
) |
| |
|
overridevirtual |
Write bytes to the socket.
- Parameters
-
buffer | these bytes are written |
len | number of bytes to write |
- Returns
- number of bytes written
- Exceptions
-
Implements tenduke::osa::Socket.
The documentation for this class was generated from the following files: