![]() |
vkmEngine 1.0.0
A C++ game engine · vkmengine.com
|
One end of one conversation: sequencing, acknowledgement and timing. More...
#include <connection.h>
Public Member Functions | |
| void | open (const NetAddress &peer) |
Point this at peer. Resets everything the last one left. | |
| void | frame (const uint8_t *payload, size_t size, std::vector< uint8_t > &out) |
Wrap payload in a header and hand it back for sending. | |
| bool | accept (const uint8_t *bytes, size_t size, std::vector< uint8_t > &payload, std::vector< uint16_t > &acknowledged) |
| Take a datagram that arrived from this peer. | |
| void | refuse () |
| Take back the acknowledgement for the packet just accepted. | |
| void | advance (float seconds) |
Age the silence timer and every unacknowledged packet by seconds of wall clock. | |
| uint16_t | nextSequence () const |
| What frame() will stamp on the next packet. | |
| float | roundTrip () const |
| Round trip, smoothed. | |
| float | lossFraction () const |
| What fraction of the peer's packets never arrived, so far. | |
| float | roundTripVariation () const |
| How much that trip varies, smoothed the same way. | |
Static Public Attributes | |
| static constexpr size_t | HEADER_BYTES = 8 |
| Bytes of header on every packet: sequence, acknowledgement, and the bitfield of the thirty-two before it. | |
| static constexpr size_t | MAX_PAYLOAD = UdpSocket::MAX_DATAGRAM - HEADER_BYTES |
| The most one packet carries past its header: what a datagram leaves. | |
| static constexpr float | TIMEOUT_SECONDS = 5.0f |
| How long silence lasts before a peer is given up on. | |
| static constexpr uint16_t | NO_SEQUENCE = 0 |
| The sequence number nothing ever sends, so a header can say "nothing". | |
One end of one conversation: sequencing, acknowledgement and timing.
Every packet carries its sequence, the newest seen the other way, and a bitfield of the thirty-two before that.
Nothing is retransmitted: the next packet says it again, newer. Acknowledgement measures the trip and what a peer holds. A packet older than one already seen is refused, or the world would mix two moments.
| void Vkm::Engine::NetConnection::frame | ( | const uint8_t * | payload, |
| size_t | size, | ||
| std::vector< uint8_t > & | out ) |
Wrap payload in a header and hand it back for sending.
The caller owns the socket, which serves every peer of a server.
| payload | What to carry; may be empty, which is a keep-alive. |
| size | Its length. |
| out | Filled with header followed by payload. |
| bool Vkm::Engine::NetConnection::accept | ( | const uint8_t * | bytes, |
| size_t | size, | ||
| std::vector< uint8_t > & | payload, | ||
| std::vector< uint16_t > & | acknowledged ) |
Take a datagram that arrived from this peer.
| bytes | The whole datagram, header included. |
| size | Its length. |
| payload | Filled with what rode inside it. |
| acknowledged | Appended with the sequences this datagram confirms, each reported once only. |
| void Vkm::Engine::NetConnection::refuse | ( | ) |
Take back the acknowledgement for the packet just accepted.
A sender reads an acknowledgement as the payload taken (see NetBaseline::confirm), so one that would not decode is un-seen here and described again.
|
inline |
What frame() will stamp on the next packet.
For a sender that must remember what that packet claimed.
|
inline |
Round trip, smoothed.
|
inline |
What fraction of the peer's packets never arrived, so far.
Counted from gaps in its sequence numbering; zero until something arrives.
|
staticconstexpr |
The sequence number nothing ever sends, so a header can say "nothing".
A sender skips it, on the first packet and on every wrap.