6#include <aegis2d/net/export.hpp>
36 std::function<void(
const Endpoint& from, std::span<const std::byte> datagram)>;
41 std::uint64_t sent = 0;
43 std::uint64_t received = 0;
45 std::uint64_t dropped = 0;
47 std::uint64_t send_errors = 0;
89 [[nodiscard]]
bool is_open() const noexcept;
97 [[nodiscard]]
Stats stats() const noexcept;
101 std::shared_ptr<Impl> impl_;
IPv4 or IPv6 address and port of a peer.
Definition endpoint.hpp:22
Runs the completion of network operations: received datagrams, finished sends.
Definition context.hpp:23
UDP socket bound to a local endpoint, receiving and sending whole datagrams.
Definition udp_socket.hpp:29
UdpSocket(NetworkContext &context, const Endpoint &local)
Opens a socket bound to a given local endpoint.
std::function< void(const Endpoint &from, std::span< const std::byte > datagram)> ReceiveHandler
Called for each datagram received.
Definition udp_socket.hpp:36
void start_receiving(ReceiveHandler handler)
Starts handing every datagram received to handler, until close().
void send_to(const Endpoint &to, std::span< const std::byte > datagram)
Sends a datagram, asynchronously. Thread-safe.
~UdpSocket()
Closes the socket.
UdpSocket & operator=(const UdpSocket &)=delete
UdpSocket & operator=(UdpSocket &&other) noexcept
Closes this socket and takes over the one of other.
void close() noexcept
Closes the socket: no more datagrams are received, pending sends are dropped.
UdpSocket(UdpSocket &&other) noexcept
Takes over the socket of other, which must not be used afterwards.
UdpSocket(NetworkContext &context, std::uint16_t port)
Opens an IPv4 socket on every local interface.
UdpSocket(const UdpSocket &)=delete
IP address and port of a network peer.
Binary serialization, UDP/TCP sockets and the network thread.
Definition binary.hpp:14
Definition endpoint.hpp:85
Event loop that runs the network operations.
Header carried by every UDP datagram, and the packet types.
Error thrown when a socket cannot be opened or bound.
Counters since the socket was opened.
Definition udp_socket.hpp:39