3es  0.7
tes::TcpListenSocket Class Reference

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...
 
TcpSocketaccept (unsigned timeoutMs=0)
 Accepts the first pending connection. More...
 
void releaseClient (TcpSocket *client)
 Disposes of a socket allocated by accept(). More...
 

Detailed Description

Represents a TCP server socket, listening for connections.

Each new connection is serviced by it's own TcpSocket, spawned from this class.

Member Function Documentation

◆ accept()

TcpSocket* tes::TcpListenSocket::accept ( unsigned  timeoutMs = 0)

Accepts the first pending connection.

This will block for the given timeout period.

Parameters
timeoutMsThe timeout to block for, awaiting new connections.
Returns
A new 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).

◆ close()

void tes::TcpListenSocket::close ( )

Close the connection and stop listening.

Spawned sockets remaining active.

Safe to call if not already listening.

◆ isListening()

bool tes::TcpListenSocket::isListening ( ) const

Checks the listening state.

Returns
true if listening for connections.

◆ listen()

bool tes::TcpListenSocket::listen ( unsigned short  port)

Start listening for connections on the specified port.

Parameters
portThe port to listen on.
Returns
true on success. Failure may be because it is already listening.

◆ releaseClient()

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.

Parameters
clientThe socket to close and release.

The documentation for this class was generated from the following file: