From 97229c181309bc91e590b84f6d898e32caf36dd2 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Wed, 9 Mar 2011 15:31:54 +0000 Subject: [PATCH] Protect against broken implementations of monotonic time. Fixes #4090. --- third-party/libutp/utp.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/third-party/libutp/utp.cpp b/third-party/libutp/utp.cpp index 8258f8d04..e7b278596 100644 --- a/third-party/libutp/utp.cpp +++ b/third-party/libutp/utp.cpp @@ -1893,10 +1893,19 @@ size_t UTP_ProcessIncoming(UTPSocket *conn, const byte *packet, size_t len, bool for (int i = 0; i < acks; ++i) { int seq = conn->seq_nr - conn->cur_window_packets + i; OutgoingPacket *pkt = (OutgoingPacket*)conn->outbuf.get(seq); + int64 rtt; if (pkt == 0 || pkt->transmissions == 0) continue; assert((int)(pkt->payload) >= 0); acked_bytes += pkt->payload; - min_rtt = min(min_rtt, UTP_GetMicroseconds() - pkt->time_sent); + rtt = UTP_GetMicroseconds() - pkt->time_sent; + if(rtt < 0) { + LOG_UTP("UTP_GetMicroseconds decreased (%ld > %ld). " + "This should not happen.", + (long)pkt->time_sent, + (long)(pkt->time_sent + rtt)); + rtt = 0; + } + min_rtt = min(min_rtt, rtt); } // count bytes acked by EACK