Browse Source

don't get stuck if clock is reset back

David Rose 22 years ago
parent
commit
f15bd7ba4f
2 changed files with 32 additions and 6 deletions
  1. 22 4
      panda/src/downloader/socketStream.I
  2. 10 2
      panda/src/net/connection.cxx

+ 22 - 4
panda/src/downloader/socketStream.I

@@ -113,10 +113,19 @@ get_collect_tcp_interval() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE bool OSocketStream::
 INLINE bool OSocketStream::
 consider_flush() {
 consider_flush() {
-  if (!_collect_tcp || 
-      ClockObject::get_global_clock()->get_real_time() - _queued_data_start >= _collect_tcp_interval) {
+  if (!_collect_tcp) {
     return flush();
     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;
   return true;
 }
 }
 
 
@@ -221,10 +230,19 @@ get_collect_tcp_interval() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE bool SocketStream::
 INLINE bool SocketStream::
 consider_flush() {
 consider_flush() {
-  if (!_collect_tcp || 
-      ClockObject::get_global_clock()->get_real_time() - _queued_data_start >= _collect_tcp_interval) {
+  if (!_collect_tcp) {
     return flush();
     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;
   return true;
 }
 }
 
 

+ 10 - 2
panda/src/net/connection.cxx

@@ -183,9 +183,17 @@ bool Connection::
 consider_flush() {
 consider_flush() {
   PR_Lock(_write_mutex);
   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();
     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);
   PR_Unlock(_write_mutex);