Runs the completion of network operations: received datagrams, finished sends.
More...
#include <aegis2d/net/context.hpp>
Runs the completion of network operations: received datagrams, finished sends.
Sockets and connections are created on a context, and their handlers are called by whichever thread calls poll(), run_for() or run() on it. The network thread (#101) calls run(); tests and tools can drive it by hand with poll() and run_for().
The context must outlive its sockets.
◆ NetworkContext() [1/3]
| aegis2d::net::NetworkContext::NetworkContext |
( |
| ) |
|
◆ NetworkContext() [2/3]
| aegis2d::net::NetworkContext::NetworkContext |
( |
const NetworkContext & |
| ) |
|
|
delete |
◆ NetworkContext() [3/3]
◆ ~NetworkContext()
| aegis2d::net::NetworkContext::~NetworkContext |
( |
| ) |
|
Destroys the context; handlers not run yet are dropped.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ poll()
| std::size_t aegis2d::net::NetworkContext::poll |
( |
| ) |
|
Runs the handlers that are ready, without waiting.
- Returns
- Number of handlers run.
◆ post()
| void aegis2d::net::NetworkContext::post |
( |
std::function< void()> |
task | ) |
|
Runs a task on the thread running the context. Thread-safe.
The game thread uses it to hand work to the network thread, for instance "send what is in the outgoing queue". Tasks run in the order they were posted. An exception thrown by task propagates out of poll(), run_for() or run().
- Parameters
-
| task | Called once, the next time the context runs its handlers. |
◆ restart()
| void aegis2d::net::NetworkContext::restart |
( |
| ) |
|
Lets the context run again after stop().
◆ run()
| void aegis2d::net::NetworkContext::run |
( |
| ) |
|
Runs handlers until stop() is called, waiting when nothing is ready.
◆ run_for()
| std::size_t aegis2d::net::NetworkContext::run_for |
( |
std::chrono::milliseconds |
duration | ) |
|
Runs handlers as they become ready, for at most duration.
Returns earlier if stop() is called or if nothing is pending.
- Parameters
-
| duration | Longest time to wait. |
- Returns
- Number of handlers run.
◆ stop()
| void aegis2d::net::NetworkContext::stop |
( |
| ) |
|
|
noexcept |
◆ stopped()
| bool aegis2d::net::NetworkContext::stopped |
( |
| ) |
const |
|
noexcept |
Tells whether stop() was called since the last restart().
- Returns
true while the context is stopped.
◆ TcpConnection
◆ TcpListener
◆ UdpSocket
The documentation for this class was generated from the following file: