+ConnectionHandler::ConnectionHandler()
+: packets_lost(0)
+, packets_received(0)
+, packet_loss(0.0f) {
+
+}
+
+void ConnectionHandler::PacketLost(uint16_t seq) {
+ OnPacketLost(seq);
+ ++packets_lost;
+ UpdatePacketLoss();
+}
+
+void ConnectionHandler::PacketReceived(uint16_t seq) {
+ OnPacketReceived(seq);
+ ++packets_received;
+ UpdatePacketLoss();
+}
+
+void ConnectionHandler::UpdatePacketLoss() noexcept {
+ unsigned int packets_total = packets_lost + packets_received;
+ if (packets_total >= 256) {
+ packet_loss = float(packets_lost) / float(packets_total);
+ packets_lost = 0;
+ packets_received = 0;
+ }
+}
+
+