|
10Duke Enterprise C++ SDK
|
#include <Socket.h>
OS-independent abstraction of a socket.
NOTE: Construction of Socket might throw tenduke::net::NetworkingException
Public Member Functions | |
| 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 | bind (std::uint32_t ipAddress, std::uint16_t port)=0 |
| Binds the 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. | |
|
pure virtual |
Accepts next connection from listening socket.
No timeout.
Implemented in AbstractBaseSocket< DESCRIPTOR_TYPE >, and tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >.
|
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.
| timeoutMs | timeout in milliseconds. Zero timeout is not yet supported. |
| tenduke::net::NetworkingException | in any case of error |
Implemented in AbstractBaseSocket< DESCRIPTOR_TYPE >, and tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >.
|
pure virtual |
Binds the socket.
| ipAddress | IP address to bind to (in host byte order) |
| port | port to bind to |
|
pure virtual |
Returns port of the socket.
|
pure virtual |
Configures the socket to listen for incoming connections.
| tenduke::net::NetworkingException | in any case of error |
Implemented in AbstractBaseSocket< DESCRIPTOR_TYPE >, and tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >.
|
pure virtual |
Reads bytes from the socket.
| buffer | buffer where the bytes are placed to |
| bufferSize | size of the buffer in bytes |
| tenduke::net::NetworkingException | in any case of error |
Implemented in AbstractBaseSocket< DESCRIPTOR_TYPE >, and tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >.
|
pure virtual |
Sets the socket to non-blocking mode.
| tenduke::net::NetworkingException | in any case of error |
|
pure virtual |
Write bytes to the socket.
| buffer | these bytes are written |
| len | number of bytes to write |
| tenduke::net::NetworkingException | in any case of error |
Implemented in AbstractBaseSocket< DESCRIPTOR_TYPE >, and tenduke::osa::AbstractBaseSocket< DESCRIPTOR_TYPE >.