From: Daniel Karbach Date: Mon, 7 Sep 2015 14:37:43 +0000 (+0200) Subject: also tell connection handlers about ack'd packets X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=b5a83cd3df5083ed0cccfe4876143e788b3836f9;p=blank.git also tell connection handlers about ack'd packets --- diff --git a/src/net/ConnectionHandler.hpp b/src/net/ConnectionHandler.hpp index 29595e5..ab9761a 100644 --- a/src/net/ConnectionHandler.hpp +++ b/src/net/ConnectionHandler.hpp @@ -13,6 +13,9 @@ class ConnectionHandler { public: void Handle(const UDPpacket &); + // called as soon as the remote end ack'd given packet + virtual void OnPacketReceived(std::uint16_t) { } + // called if the remote end probably didn't get given packet virtual void OnPacketLost(std::uint16_t) { } virtual void OnTimeout() { } diff --git a/src/net/Packet.hpp b/src/net/Packet.hpp index 0dab949..4ff45df 100644 --- a/src/net/Packet.hpp +++ b/src/net/Packet.hpp @@ -21,6 +21,11 @@ struct Packet { std::uint16_t seq; std::uint16_t ack; std::uint32_t hist; + + // true if this contains an ack for given (remote) seq + bool Acks(std::uint16_t) const noexcept; + std::uint16_t AckBegin() const noexcept { return ack; } + std::uint16_t AckEnd() const noexcept { return ack + std::uint16_t(33); } }; struct Header { diff --git a/src/net/net.cpp b/src/net/net.cpp index 837a7fb..1876157 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -271,10 +271,23 @@ void Connection::Received(const UDPpacket &udp_pack) { } } } + // check for newly ack'd packets + for (uint16_t s = ctrl_new.AckBegin(); s != ctrl_new.AckEnd(); ++s) { + if (ctrl_new.Acks(s) && !ctrl_in.Acks(s)) { + Handler().OnPacketReceived(s); + } + } ctrl_in = ctrl_new; } } +bool Packet::TControl::Acks(uint16_t s) const noexcept { + int16_t diff = int16_t(ack) - int16_t(s); + if (diff == 0) return true; + if (diff < 0 || diff > 32) return false; + return (hist & (1 << (diff - 1))) != 0; +} + uint16_t Connection::SendPing(UDPpacket &udp_pack, UDPsocket sock) { Packet::Make(udp_pack); return Send(udp_pack, sock);