#include <AbstractBaseSocket.h>
template<typename DESCRIPTOR_TYPE>
class AbstractBaseSocket< DESCRIPTOR_TYPE >
Abstract base implementation of tenduke::osa::Socket.
|
|
| AbstractBaseSocket (const AbstractBaseSocket &)=delete |
| |
|
| AbstractBaseSocket (const DESCRIPTOR_TYPE descriptor) |
| | Constructs a new socket.
|
| |
|
AbstractBaseSocket & | operator= (const AbstractBaseSocket &)=delete |
| |
| std::unique_ptr<::tenduke::osa::Socket > | accept (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
-
| timeoutMs | timeout in milliseconds. Zero timeout is not yet supported. |
- Returns
- the child socket or
nullptr if accept timed out
- Exceptions
-
|
| |
| virtual std::unique_ptr< Socket > | accept ()=0 |
| | Accepts next connection from listening socket.
|
| |
| void | listen () override |
| | Configures the socket to listen for incoming connections.- Exceptions
-
|
| |
| int | read (void *buffer, const 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, const 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 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.
|
| |
|
| 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 struct::timeval | timeFromMilliseconds (const std::uint32_t milliseconds) |
| | Returns struct timeval populated from milliseconds.
|
| |
|
|
DESCRIPTOR_TYPE | descriptor |
| | The socket descriptor.
|
| |
◆ 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>
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.
◆ getLastError()
template<typename DESCRIPTOR_TYPE>
Returns last error code.
- Returns
- -
◆ hasIncomingConnections()
template<typename DESCRIPTOR_TYPE>
Checks if the socket has incoming connections.
The check will wait for incoming connections for the specified timeout.
- Parameters
-
| timeoutMs | timeout in milliseconds |
- Returns
true if there are incoming connections, false otherwise
- Exceptions
-
◆ listen()
template<typename DESCRIPTOR_TYPE>
Configures the socket to listen for incoming connections.
- Exceptions
-
Implements tenduke::osa::Socket.
◆ mkErrorMessage() [1/3]
template<typename DESCRIPTOR_TYPE>
Builds error message.
- Parameters
-
- Returns
- -
◆ mkErrorMessage() [2/3]
template<typename DESCRIPTOR_TYPE>
Builds error message.
- Parameters
-
- Returns
- -
◆ mkErrorMessage() [3/3]
template<typename DESCRIPTOR_TYPE>
Builds error message.
- Parameters
-
- Returns
- -
◆ read()
template<typename DESCRIPTOR_TYPE>
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.
◆ timeFromMilliseconds()
template<typename DESCRIPTOR_TYPE>
Returns struct timeval populated from milliseconds.
- Parameters
-
- Returns
- -
◆ wouldBlock()
template<typename DESCRIPTOR_TYPE>
Checks if error code means that call would have blocked.
- Parameters
-
- Returns
- -
◆ write()
template<typename DESCRIPTOR_TYPE>
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 file: