Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
network_thread.hpp
Go to the documentation of this file.
1
3#pragma once
5#include <aegis2d/net/export.hpp>
6
7#include <atomic>
8#include <cstdint>
9#include <thread>
10
11namespace aegis2d::net {
12
30class AEGIS2D_NET_EXPORT NetworkThread {
31public:
35 explicit NetworkThread(NetworkContext& context);
36
37 NetworkThread(const NetworkThread&) = delete;
43
48 void stop();
49
52 [[nodiscard]] bool running() const noexcept;
53
56 [[nodiscard]] bool is_network_thread() const noexcept;
57
60 [[nodiscard]] std::uint64_t errors() const noexcept;
61
62private:
63 void run();
64 void join() noexcept;
65
66 NetworkContext& context_;
67 std::atomic<std::uint64_t> errors_{0};
68 std::atomic<bool> running_{true};
69 std::thread thread_;
70};
71
72} // namespace aegis2d::net
Runs the completion of network operations: received datagrams, finished sends.
Definition context.hpp:23
Runs a NetworkContext on a thread of its own, until stopped.
Definition network_thread.hpp:30
NetworkThread & operator=(NetworkThread &&)=delete
NetworkThread & operator=(const NetworkThread &)=delete
~NetworkThread()
Stops the context and waits for the thread to finish.
bool running() const noexcept
Tells whether the thread is running.
NetworkThread(NetworkContext &context)
Starts a thread running context.
NetworkThread(const NetworkThread &)=delete
void stop()
Stops the context and waits for the thread to finish.
NetworkThread(NetworkThread &&)=delete
Binary serialization, UDP/TCP sockets and the network thread.
Definition binary.hpp:14
Definition endpoint.hpp:85
Event loop that runs the network operations.