diff --git a/panda/src/downloader/httpChannel.I b/panda/src/downloader/httpChannel.I index c43da782b1..4f21354f89 100644 --- a/panda/src/downloader/httpChannel.I +++ b/panda/src/downloader/httpChannel.I @@ -275,6 +275,28 @@ get_file_size() const { return _file_size; } +//////////////////////////////////////////////////////////////////// +// Function: HTTPChannel::reset +// Access: Published +// Description: Stops whatever file transaction is currently in +// progress, closes the connection, and resets to begin +// anew. You shouldn't ever need to call this, since +// the channel should be able to reset itself cleanly +// between requests, but it is provided in case you are +// an especially nervous type. +// +// Don't call this after every request unless you set +// set_persistent_connection() to false, since calling +// reset() rudely closes the connection regardless of +// whether we have told the server we intend to keep it +// open or not. +//////////////////////////////////////////////////////////////////// +INLINE void HTTPChannel:: +reset() { + reset_for_new_request(); + free_bio(); +} + //////////////////////////////////////////////////////////////////// // Function: HTTPChannel::post_form // Access: Published diff --git a/panda/src/downloader/httpChannel.cxx b/panda/src/downloader/httpChannel.cxx index 42c5d654e8..67a1fcc8d1 100644 --- a/panda/src/downloader/httpChannel.cxx +++ b/panda/src/downloader/httpChannel.cxx @@ -1214,13 +1214,7 @@ run_download_to_ram() { void HTTPChannel:: begin_request(const string &method, const URLSpec &url, const string &body, bool nonblocking, size_t first_byte, size_t last_byte) { - reset_download_to(); - _status_code = 0; - _status_string = string(); - _redirect_trail.clear(); - _last_status_code = 0; - _file_size = 0; - _bytes_downloaded = 0; + reset_for_new_request(); // Changing the proxy, or the nonblocking state, is grounds for // dropping the old connection, if any. @@ -1276,6 +1270,23 @@ begin_request(const string &method, const URLSpec &url, const string &body, _done_state = S_read_header; } +//////////////////////////////////////////////////////////////////// +// Function: HTTPChannel::reset_for_new_request +// Access: Private +// Description: Resets the internal state variables in preparation +// for beginning a new request. +//////////////////////////////////////////////////////////////////// +void HTTPChannel:: +reset_for_new_request() { + reset_download_to(); + _status_code = 0; + _status_string = string(); + _redirect_trail.clear(); + _last_status_code = 0; + _file_size = 0; + _bytes_downloaded = 0; +} + //////////////////////////////////////////////////////////////////// // Function: HTTPChannel::http_getline // Access: Private diff --git a/panda/src/downloader/httpChannel.h b/panda/src/downloader/httpChannel.h index b58b28271a..62d138f640 100644 --- a/panda/src/downloader/httpChannel.h +++ b/panda/src/downloader/httpChannel.h @@ -99,6 +99,8 @@ PUBLISHED: void write_headers(ostream &out) const; + INLINE void reset(); + INLINE bool post_form(const URLSpec &url, const string &body); INLINE bool get_document(const URLSpec &url); INLINE bool get_subdocument(const URLSpec &url, @@ -142,6 +144,7 @@ private: void begin_request(const string &method, const URLSpec &url, const string &body, bool nonblocking, size_t first_byte, size_t last_byte); + void reset_for_new_request(); bool http_getline(string &str); bool http_send(const string &str);