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
4
#include <
aegis2d/net/context.hpp
>
5
#include <aegis2d/net/export.hpp>
6
7
#include <atomic>
8
#include <cstdint>
9
#include <thread>
10
11
namespace
aegis2d::net
{
12
30
class
AEGIS2D_NET_EXPORT
NetworkThread
{
31
public
:
35
explicit
NetworkThread
(
NetworkContext
& context);
36
37
NetworkThread
(
const
NetworkThread
&) =
delete
;
38
NetworkThread
&
operator=
(
const
NetworkThread
&) =
delete
;
39
NetworkThread
(
NetworkThread
&&) =
delete
;
40
NetworkThread
&
operator=
(
NetworkThread
&&) =
delete
;
42
~NetworkThread
();
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
62
private:
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
aegis2d::net::NetworkContext
Runs the completion of network operations: received datagrams, finished sends.
Definition
context.hpp:23
aegis2d::net::NetworkThread
Runs a NetworkContext on a thread of its own, until stopped.
Definition
network_thread.hpp:30
aegis2d::net::NetworkThread::operator=
NetworkThread & operator=(NetworkThread &&)=delete
aegis2d::net::NetworkThread::operator=
NetworkThread & operator=(const NetworkThread &)=delete
aegis2d::net::NetworkThread::~NetworkThread
~NetworkThread()
Stops the context and waits for the thread to finish.
aegis2d::net::NetworkThread::running
bool running() const noexcept
Tells whether the thread is running.
aegis2d::net::NetworkThread::NetworkThread
NetworkThread(NetworkContext &context)
Starts a thread running context.
aegis2d::net::NetworkThread::NetworkThread
NetworkThread(const NetworkThread &)=delete
aegis2d::net::NetworkThread::stop
void stop()
Stops the context and waits for the thread to finish.
aegis2d::net::NetworkThread::NetworkThread
NetworkThread(NetworkThread &&)=delete
aegis2d::net
Binary serialization, UDP/TCP sockets and the network thread.
Definition
binary.hpp:14
std
Definition
endpoint.hpp:85
context.hpp
Event loop that runs the network operations.
aegis2d
net
network_thread.hpp
Generated by
1.9.8