#include <Socket.h>
OS-independent abstraction of a socket.
NOTE: Construction of Socket might throw tenduke::net::NetworkingException
|
| virtual std::unique_ptr< Socket > | accept (uint32_t timeoutMs)=0 |
| | Accepts next connection from listening socket, with a timeout.
|
| |
| virtual std::unique_ptr< Socket > | accept ()=0 |
| | Accepts next connection from listening socket.
|
| |
| virtual void | listen ()=0 |
| | Configures the socket to listen for incoming connections.
|
| |
| virtual int | read (void *buffer, std::size_t bufferSize)=0 |
| | Reads bytes from the socket.
|
| |
| virtual int | write (const void *buffer, std::size_t len)=0 |
| | Write bytes to 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.
|
| |
◆ accept() [1/2]
| virtual std::unique_ptr< Socket > tenduke::osa::Socket::accept |
( |
| ) |
|
|
pure virtual |
Accepts next connection from listening socket.
No timeout.
- Returns
- the child socket
◆ accept() [2/2]
| virtual std::unique_ptr< Socket > tenduke::osa::Socket::accept |
( |
uint32_t | timeoutMs | ) |
|
|
pure virtual |
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
-
◆ getPort()
| virtual std::uint16_t tenduke::osa::Socket::getPort |
( |
| ) |
const |
|
pure virtual |
Returns port of the socket.
- Returns
- the port number
◆ listen()
| virtual void tenduke::osa::Socket::listen |
( |
| ) |
|
|
pure virtual |
Configures the socket to listen for incoming connections.
- Exceptions
-
◆ read()
| virtual int tenduke::osa::Socket::read |
( |
void * | buffer, |
|
|
std::size_t | bufferSize ) |
|
pure virtual |
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
-
◆ setNonBlocking()
| virtual void tenduke::osa::Socket::setNonBlocking |
( |
| ) |
|
|
pure virtual |
Sets the socket to non-blocking mode.
- Exceptions
-
◆ write()
| virtual int tenduke::osa::Socket::write |
( |
const void * | buffer, |
|
|
std::size_t | len ) |
|
pure virtual |
Write bytes to the socket.
- Parameters
-
| buffer | these bytes are written |
| len | number of bytes to write |
- Returns
- number of bytes written
- Exceptions
-
The documentation for this class was generated from the following file: