Browse Source

*** empty log message ***

Joe Shochet 25 years ago
parent
commit
a3c5838dea
2 changed files with 58 additions and 11 deletions
  1. 6 6
      panda/src/downloader/downloadDb.cxx
  2. 52 5
      panda/src/downloader/downloader.cxx

+ 6 - 6
panda/src/downloader/downloadDb.cxx

@@ -606,7 +606,7 @@ parse_record_header(uchar *start, int size) {
 
   DatagramIterator di(_datagram);
   PN_int32 record_length = di.get_int32();
-  downloader_cat.debug()
+  downloader_cat.spam()
     << "Parsed record header length: " << record_length << endl;
 
   // If we got all the way here, must be done
@@ -666,7 +666,7 @@ parse_fr(uchar *start, int size) {
   fr->_name = di.extract_bytes(fr_name_length);
   fr->_version = di.get_int32();
   
-  downloader_cat.debug()
+  downloader_cat.spam()
     << "Parsed file record: " << fr->_name 
     << " version: " << fr->_version 
     << " hash: " << fr->_hash 
@@ -1017,7 +1017,7 @@ write_version_map(ofstream &write_stream) {
   _master_datagram.add_int32(_versions.size());
   for (vmi = _versions.begin(); vmi != _versions.end(); ++vmi) {
     string name = (*vmi).first;
-    downloader_cat.debug()
+    downloader_cat.spam()
       << "DownloadDb::write_version_map() - writing file: "
       << name << " of length: " << name.length() << endl;
     _master_datagram.add_int32(name.length());
@@ -1059,7 +1059,7 @@ read_version_map(ifstream &read_stream) {
     _master_datagram.append_data(buffer, sizeof(PN_int32)); 
     DatagramIterator di2(_master_datagram);
     int name_length = di2.get_int32();
-    downloader_cat.debug()
+    downloader_cat.spam()
       << "DownloadDb::read_version_map() - name length: " << name_length
       << endl;
 
@@ -1070,7 +1070,7 @@ read_version_map(ifstream &read_stream) {
     _master_datagram.append_data(namebuffer, name_length);
     DatagramIterator di4(_master_datagram);
     string name = di4.extract_bytes(name_length);
-    downloader_cat.debug()
+    downloader_cat.spam()
       << "DownloadDb::read_version_map() - name: " << name << endl;
 
     // Get number of hash values for name
@@ -1079,7 +1079,7 @@ read_version_map(ifstream &read_stream) {
     _master_datagram.append_data(buffer, sizeof(PN_int32));
     DatagramIterator di5(_master_datagram);
     int length = di5.get_int32();   
-    downloader_cat.debug()
+    downloader_cat.spam()
       << "DownloadDb::read_version_map() - number of values: " << length
       << endl;
 

+ 52 - 5
panda/src/downloader/downloader.cxx

@@ -540,6 +540,7 @@ download(const string &file_name, Filename file_dest,
   DownloadStatus status(_buffer->_buffer, event_name, first_byte, last_byte,
 			total_bytes, partial_content, id);
   bool got_any_data = false;
+  bool timeout_updated_bytes_in_buffer = false;
   
   for (;;) {
     if (_download_enabled) { 
@@ -573,13 +574,51 @@ download(const string &file_name, Filename file_dest,
       // Handle receive timeouts by trying again
       if (ans == RS_timeout) {
 	int extra_bytes = 0;
+
+	if (bytes > 0) {
+	  status._bytes_in_buffer += bytes;
+	  status._next_in += bytes;
+	  got_any_data = true;
+	  timeout_updated_bytes_in_buffer = true;
+	}
+
+	// Ensure we have enough room in the buffer to download read_size
+	// If we don't have enough room, write the buffer to disk
+	if (status._bytes_in_buffer + read_size > _buffer_size) {
+	  if (downloader_cat.is_debug())
+	    downloader_cat.debug()
+	      << "Downloader::download() - Flushing buffer" << endl;
+	  if (write_to_disk(status) == false)
+	    return false;
+	}
+
 	for (int r = 0; r < downloader_timeout_retries; r++) {
+	    extra_bytes = 0;
+
+	    // Ensure we have enough room in the buffer to download read_size
+	    // If we don't have enough room, write the buffer to disk
+	    if (status._bytes_in_buffer + read_size > _buffer_size) {
+	      if (downloader_cat.is_debug())
+		downloader_cat.debug()
+		  << "Downloader::download() - Flushing buffer" << endl;
+	      if (write_to_disk(status) == false)
+		return false;
+	    }
+
 	    ans = safe_receive(_socket, status._next_in, read_size,
 					(long)downloader_timeout, extra_bytes);
+
+	    if (extra_bytes > 0) {
+	      bytes += extra_bytes;
+	      status._bytes_in_buffer += bytes;
+	      status._next_in += bytes;
+	      got_any_data = true;
+	      timeout_updated_bytes_in_buffer = true;
+	    }
+
 	    if (ans != RS_timeout)
 	      break;
 	}
-	bytes += extra_bytes;
 
 	if (ans == RS_timeout) {
 	  // We've really timed out - throw an event
@@ -641,13 +680,21 @@ download(const string &file_name, Filename file_dest,
 	if (downloader_cat.is_debug())
 	  downloader_cat.debug()
 	    << "Downloader::download() - Got: " << bytes << " bytes" << endl;
-	status._bytes_in_buffer += bytes;
-   	status._next_in += bytes;
-	got_any_data = true;
 
+	// If the timeout read data and already updated these variables
+	// we do not want to update them again
+	if (timeout_updated_bytes_in_buffer == true) {
+	  // reset this variable and do not update the byte count
+	  timeout_updated_bytes_in_buffer = false;
+	} else {
+	  status._bytes_in_buffer += bytes;
+	  status._next_in += bytes;
+	  got_any_data = true;
+	}
+	
 	// Sleep for the requested frequency
 	nap();
-      }
+	}
     }
   }
 }