3es
0.7
|
Represents a TCP server socket, listening for connections. More...
#include <3estcplistensocket.h>
Public Member Functions | |
TcpListenSocket () | |
Constructor. | |
~TcpListenSocket () | |
Destructor. | |
bool | listen (unsigned short port) |
Start listening for connections on the specified port. More... | |
void | close () |
Close the connection and stop listening. More... | |
bool | isListening () const |
Checks the listening state. More... | |
TcpSocket * | accept (unsigned timeoutMs=0) |
Accepts the first pending connection. More... | |
void | releaseClient (TcpSocket *client) |
Disposes of a socket allocated by accept() . More... | |
Represents a TCP server socket, listening for connections.
Each new connection is serviced by it's own TcpSocket
, spawned from this class.
TcpSocket* tes::TcpListenSocket::accept | ( | unsigned | timeoutMs = 0 | ) |
Accepts the first pending connection.
This will block for the given timeout period.
timeoutMs | The timeout to block for, awaiting new connections. |
TcpSocket
representing the accepted connection, or nullptr
if there are not pending connections. The caller takes ownership of the socket and must delete it when done either by invoking delete
, or by calling releaseClient()
(preferred). void tes::TcpListenSocket::close | ( | ) |
Close the connection and stop listening.
Spawned sockets remaining active.
Safe to call if not already listening.
bool tes::TcpListenSocket::isListening | ( | ) | const |
Checks the listening state.
true
if listening for connections. bool tes::TcpListenSocket::listen | ( | unsigned short | port | ) |
Start listening for connections on the specified port.
port | The port to listen on. |
true
on success. Failure may be because it is already listening. void tes::TcpListenSocket::releaseClient | ( | TcpSocket * | client | ) |
Disposes of a socket allocated by accept()
.
This is safer than invoking delete
on the socket, because it ensures the same allocator is used to dispose of the socket.
client | The socket to close and release. |