#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 |
◆ 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
-
Implemented in FakeSocket, tenduke::osa::AbstractBaseSocket, and tenduke::test::fakes::FakeSocket.
◆ getPort()
| virtual std::uint16_t tenduke::osa::Socket::getPort |
( |
| ) |
const |
|
pure virtual |
◆ listen()
| virtual void tenduke::osa::Socket::listen |
( |
| ) |
|
|
pure virtual |
◆ read()
| virtual int tenduke::osa::Socket::read |
( |
void * | buffer, |
|
|
std::size_t | bufferSize ) |
|
pure virtual |
◆ setNonBlocking()
| virtual void tenduke::osa::Socket::setNonBlocking |
( |
| ) |
|
|
pure virtual |
◆ write()
| virtual int tenduke::osa::Socket::write |
( |
const void * | buffer, |
|
|
std::size_t | len ) |
|
pure virtual |
The documentation for this class was generated from the following file: