+void ConnectionHandler::PacketIn(const UDPpacket &pack) noexcept {
+ rx_bytes += pack.len + 20; // I know, I know, it's an estimate (about 48 for IPv6)
+ UpdateStats();
+}
+
+void ConnectionHandler::PacketOut(const UDPpacket &pack) noexcept {
+ tx_bytes += pack.len + 20;
+ UpdateStats();
+}
+
+void ConnectionHandler::UpdateStats() noexcept {
+ Uint32 now = SDL_GetTicks();
+ if (now >= next_sample) {
+ tx_kbps = float(tx_bytes) * (1.0f / 1024.0f);
+ rx_kbps = float(rx_bytes) * (1.0f / 1024.0f);
+ tx_bytes = 0;
+ rx_bytes = 0;
+ next_sample += 1000;
+ }
+}
+