Procházet zdrojové kódy

add preserve_status

David Rose před 22 roky
rodič
revize
ee62734534

+ 22 - 0
panda/src/downloader/httpChannel.I

@@ -510,8 +510,30 @@ INLINE void HTTPChannel::
 reset() {
   reset_for_new_request();
   reset_to_new();
+  _status_list.clear();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: HTTPChannel::preserve_status
+//       Access: Published
+//  Description: Preserves the previous status code (presumably a
+//               failure) from the previous connection attempt.  If
+//               the subsequent connection attempt also fails, the
+//               returned status code will be the better of the
+//               previous code and the current code.
+//
+//               This can be called to daisy-chain subsequent attempts
+//               to download the same document from different servers.
+//               After all servers have been attempted, the final
+//               status code will reflect the attempt that most nearly
+//               succeeded.
+////////////////////////////////////////////////////////////////////
+INLINE void HTTPChannel::
+preserve_status() {
+  _status_list.push_back(_status_entry);
+}
+
+
 ////////////////////////////////////////////////////////////////////
 //     Function: HTTPChannel::clear_extra_headers
 //       Access: Published

+ 7 - 3
panda/src/downloader/httpChannel.cxx

@@ -757,11 +757,16 @@ reached_done_state() {
         }
       }
       _status_entry = _status_list[best_i];
+      _status_list.clear();
     }
 
     return false;
+  }
+
+  // We don't need the list of previous failures any more--we've connected.
+  _status_list.clear();
 
-  } else if (_download_dest == DD_none) {
+  if (_download_dest == DD_none) {
     // All done.
     return false;
     
@@ -806,7 +811,7 @@ run_try_next_proxy() {
     close_connection();
     reconsider_proxy();
     _state = S_connecting;
-    nassertr(_status_list.size() == _proxy_next_index - 1, false);
+
     return false;
   }
 
@@ -2170,7 +2175,6 @@ reset_for_new_request() {
 
   _last_status_code = 0;
   _status_entry = StatusEntry();
-  _status_list.clear();
 
   _response_type = RT_none;
   _redirect_trail.clear();

+ 1 - 0
panda/src/downloader/httpChannel.h

@@ -147,6 +147,7 @@ PUBLISHED:
   void write_headers(ostream &out) const;
 
   INLINE void reset();
+  INLINE void preserve_status();
 
   INLINE void clear_extra_headers();
   INLINE void send_extra_header(const string &key, const string &value);