![]() |
vkmEngine 1.0.0
A C++ game engine · vkmengine.com
|
A non-blocking UDP socket, the same on Windows and Linux. More...
#include <udp_socket.h>
Public Member Functions | |
| bool | open (uint16_t port) |
| Take a port and start listening on every interface. | |
| void | close () |
| Close it. Safe to call on one that was never opened. | |
| bool | send (const NetAddress &to, const uint8_t *bytes, size_t size) |
Send size bytes to to. | |
| bool | receive (std::vector< uint8_t > &out, NetAddress &from) |
| Take the next datagram, if one is waiting. | |
| NetAddress | localAddress () const |
| Loopback and the port this is bound to, including one the system picked for zero. | |
Static Public Attributes | |
| static constexpr size_t | MAX_DATAGRAM = 1200 |
| The largest datagram this will send. | |
A non-blocking UDP socket, the same on Windows and Linux.
The whole Winsock/BSD difference sits behind this type. Non-blocking, so a frame never stalls on the network.
|
nodiscard |
Take a port and start listening on every interface.
| port | Port to bind, or 0 to let the system choose a free one. |
| bool Vkm::Engine::UdpSocket::send | ( | const NetAddress & | to, |
| const uint8_t * | bytes, | ||
| size_t | size ) |
Send size bytes to to.
Refused past MAX_DATAGRAM.
| to | Where it goes. |
| bytes | The payload. |
| size | Payload length in bytes. |
|
nodiscard |
Take the next datagram, if one is waiting.
One datagram per call. An empty or oversized one answers true with out empty, so a caller's per-frame read bound counts it.
| out | Filled with the payload; cleared first. |
| from | Filled with where it came from. |
|
inline |
Loopback and the port this is bound to, including one the system picked for zero.
127.0.0.1 rather than the bound 0.0.0.0, which nothing can send to.
|
staticconstexpr |
The largest datagram this will send.
Inside the smallest path MTU worth designing for, with room for the IP and UDP headers. Past it IP fragments, and one lost fragment loses the whole datagram.