diff --git a/panda/src/downloader/socketStream.I b/panda/src/downloader/socketStream.I index 960f1607f7..bb8d91cdce 100644 --- a/panda/src/downloader/socketStream.I +++ b/panda/src/downloader/socketStream.I @@ -113,10 +113,19 @@ get_collect_tcp_interval() const { //////////////////////////////////////////////////////////////////// INLINE bool OSocketStream:: consider_flush() { - if (!_collect_tcp || - ClockObject::get_global_clock()->get_real_time() - _queued_data_start >= _collect_tcp_interval) { + if (!_collect_tcp) { return flush(); + + } else { + double elapsed = + ClockObject::get_global_clock()->get_real_time() - _queued_data_start; + // If the elapsed time is negative, someone must have reset the + // clock back, so just go ahead and flush. + if (elapsed < 0.0 || elapsed >= _collect_tcp_interval) { + return flush(); + } } + return true; } @@ -221,10 +230,19 @@ get_collect_tcp_interval() const { //////////////////////////////////////////////////////////////////// INLINE bool SocketStream:: consider_flush() { - if (!_collect_tcp || - ClockObject::get_global_clock()->get_real_time() - _queued_data_start >= _collect_tcp_interval) { + if (!_collect_tcp) { return flush(); + + } else { + double elapsed = + ClockObject::get_global_clock()->get_real_time() - _queued_data_start; + // If the elapsed time is negative, someone must have reset the + // clock back, so just go ahead and flush. + if (elapsed < 0.0 || elapsed >= _collect_tcp_interval) { + return flush(); + } } + return true; } diff --git a/panda/src/net/connection.cxx b/panda/src/net/connection.cxx index 2d149d5d51..6ff09230e5 100644 --- a/panda/src/net/connection.cxx +++ b/panda/src/net/connection.cxx @@ -183,9 +183,17 @@ bool Connection:: consider_flush() { PR_Lock(_write_mutex); - if (!_collect_tcp || - ClockObject::get_global_clock()->get_real_time() - _queued_data_start >= _collect_tcp_interval) { + if (!_collect_tcp) { return do_flush(); + + } else { + double elapsed = + ClockObject::get_global_clock()->get_real_time() - _queued_data_start; + // If the elapsed time is negative, someone must have reset the + // clock back, so just go ahead and flush. + if (elapsed < 0.0 || elapsed >= _collect_tcp_interval) { + return do_flush(); + } } PR_Unlock(_write_mutex);