Listening TCP socket handing every accepted peer over as a TcpConnection.
More...
#include <aegis2d/net/tcp_connection.hpp>
Listening TCP socket handing every accepted peer over as a TcpConnection.
Once start_accepting() is called, each connection accepted is given to the handler, on the thread running the NetworkContext; the handler owns it from then on and calls TcpConnection::start() to read from it. Accepting goes on after errors. Create, close and destroy the listener on the thread that runs the context, or while the context is not running.
◆ AcceptHandler
Called for each connection accepted.
An exception thrown by the handler leaves the listener accepting and propagates out of the context's poll(), run_for() or run().
◆ TcpListener() [1/4]
| aegis2d::net::TcpListener::TcpListener |
( |
NetworkContext & |
context, |
|
|
std::uint16_t |
port |
|
) |
| |
Listens on every IPv4 interface.
- Parameters
-
| context | Context that runs the listener's operations and its connections'; it must outlive them. |
| port | Local port, or 0 for any free port. |
- Exceptions
-
| SocketError | if the port is already in use or cannot be bound. |
◆ TcpListener() [2/4]
Listens on a given local endpoint.
- Parameters
-
| context | Context that runs the listener's operations and its connections'; it must outlive them. |
| local | Local address and port, IPv4 or IPv6; port 0 picks a free port. |
- Exceptions
-
| SocketError | if the endpoint is already in use or cannot be bound. |
◆ TcpListener() [3/4]
| aegis2d::net::TcpListener::TcpListener |
( |
const TcpListener & |
| ) |
|
|
delete |
◆ TcpListener() [4/4]
| aegis2d::net::TcpListener::TcpListener |
( |
TcpListener && |
other | ) |
|
|
noexcept |
Takes over the listener of other, which must not be used afterwards.
◆ ~TcpListener()
| aegis2d::net::TcpListener::~TcpListener |
( |
| ) |
|
Stops listening; connections already accepted stay open.
◆ close()
| void aegis2d::net::TcpListener::close |
( |
| ) |
|
|
noexcept |
Stops listening; connections already accepted stay open.
◆ is_open()
| bool aegis2d::net::TcpListener::is_open |
( |
| ) |
const |
|
noexcept |
Tells whether the listener is open.
- Returns
false after close().
◆ local_endpoint()
| Endpoint aegis2d::net::TcpListener::local_endpoint |
( |
| ) |
const |
Local address and port, with the port the system picked if 0 was asked.
- Returns
- The bound endpoint.
◆ operator=() [1/2]
◆ operator=() [2/2]
Closes this listener and takes over the one of other.
- Returns
- This listener.
◆ start_accepting()
| void aegis2d::net::TcpListener::start_accepting |
( |
AcceptHandler |
handler | ) |
|
Starts handing every accepted connection to handler, until close().
- Parameters
-
| handler | Called on the context's thread for each connection. |
The documentation for this class was generated from the following file: