Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
context.hpp
Go to the documentation of this file.
1
3#pragma once
4#include <aegis2d/net/export.hpp>
5
6#include <chrono>
7#include <cstddef>
8#include <functional>
9#include <memory>
10
11namespace aegis2d::net {
12
13class TcpConnection;
14class TcpListener;
15class UdpSocket;
16
23class AEGIS2D_NET_EXPORT NetworkContext {
24public:
33
36 std::size_t poll();
37
42 std::size_t run_for(std::chrono::milliseconds duration);
43
45 void run();
46
49 void stop() noexcept;
50
53 [[nodiscard]] bool stopped() const noexcept;
54
56 void restart();
57
63 void post(std::function<void()> task);
64
65private:
66 friend class TcpConnection;
67 friend class TcpListener;
68 friend class UdpSocket;
69 struct Impl;
70 std::unique_ptr<Impl> impl_;
71};
72
73} // namespace aegis2d::net
Runs the completion of network operations: received datagrams, finished sends.
Definition context.hpp:23
NetworkContext(NetworkContext &&)=delete
NetworkContext()
Creates an idle context.
void stop() noexcept
Makes run(), run_for() and poll() return as soon as possible. Thread-safe.
NetworkContext & operator=(NetworkContext &&)=delete
NetworkContext(const NetworkContext &)=delete
void run()
Runs handlers until stop() is called, waiting when nothing is ready.
NetworkContext & operator=(const NetworkContext &)=delete
std::size_t poll()
Runs the handlers that are ready, without waiting.
~NetworkContext()
Destroys the context; handlers not run yet are dropped.
std::size_t run_for(std::chrono::milliseconds duration)
Runs handlers as they become ready, for at most duration.
TCP connection exchanging whole messages over the byte stream.
Definition tcp_connection.hpp:51
Listening TCP socket handing every accepted peer over as a TcpConnection.
Definition tcp_connection.hpp:150
UDP socket bound to a local endpoint, receiving and sending whole datagrams.
Definition udp_socket.hpp:29
Binary serialization, UDP/TCP sockets and the network thread.
Definition binary.hpp:14
Definition endpoint.hpp:85