diff --git a/panda/src/downloader/httpChannel.I b/panda/src/downloader/httpChannel.I index 37172397f9..0d147be377 100644 --- a/panda/src/downloader/httpChannel.I +++ b/panda/src/downloader/httpChannel.I @@ -438,6 +438,30 @@ get_bytes_downloaded() const { return _bytes_downloaded; } +//////////////////////////////////////////////////////////////////// +// Function: HTTPChannel::get_bytes_requested +// Access: Published +// Description: When download throttling is in effect +// (set_download_throttle() has been set to true) and +// non-blocking I/O methods (like begin_get_document()) +// are used, this returns the number of bytes +// "requested" from the server so far: that is, the +// theoretical maximum value for get_bytes_downloaded(), +// if the server has been keeping up with our demand. +// +// If this number is less than get_bytes_downloaded(), +// then the server has not been supplying bytes fast +// enough to meet our own download throttle rate. +// +// When download throttling is not in effect, or when +// the blocking I/O methods (like get_document(), etc.) +// are used, this returns 0. +//////////////////////////////////////////////////////////////////// +INLINE size_t HTTPChannel:: +get_bytes_requested() const { + return _bytes_requested; +} + //////////////////////////////////////////////////////////////////// // Function: HTTPChannel::is_download_complete // Access: Published @@ -446,6 +470,14 @@ get_bytes_downloaded() const { // fully downloaded. If this still returns false after // processing has completed, there was an error in // transmission. +// +// Note that simply testing is_download_complete() does +// not prove that the requested document was succesfully +// retrieved--you might have just downloaded the "404 +// not found" stub (for instance) that a server would +// provide in response to some error condition. You +// should also check is_valid() to prove that the file +// you expected has been successfully retrieved. //////////////////////////////////////////////////////////////////// INLINE bool HTTPChannel:: is_download_complete() const { diff --git a/panda/src/downloader/httpChannel.cxx b/panda/src/downloader/httpChannel.cxx index 928806b53c..3ca99c22b9 100644 --- a/panda/src/downloader/httpChannel.cxx +++ b/panda/src/downloader/httpChannel.cxx @@ -61,6 +61,7 @@ HTTPChannel(HTTPClient *client) : _read_index = 0; _file_size = 0; _bytes_downloaded = 0; + _bytes_requested = 0; _status_code = 0; _status_string = string(); _proxy = _client->get_proxy(); @@ -221,6 +222,7 @@ run() { // Come back later. return true; } + _bytes_requested += _bytes_per_update; } switch (_download_dest) { case DD_none: @@ -1142,7 +1144,7 @@ run_download_to_file() { while (!_body_stream->eof() && !_body_stream->fail()) { _download_to_file.put(ch); _bytes_downloaded++; - if (do_throttle && (++count > _bytes_per_update)) { + if (do_throttle && (++count >= _bytes_per_update)) { // That's enough for now. return true; } @@ -1186,7 +1188,7 @@ run_download_to_ram() { while (!_body_stream->eof() && !_body_stream->fail()) { _download_to_ramfile->_data += (char)ch; _bytes_downloaded++; - if (do_throttle && (++count > _bytes_per_update)) { + if (do_throttle && (++count >= _bytes_per_update)) { // That's enough for now. return true; } @@ -1285,6 +1287,7 @@ reset_for_new_request() { _last_status_code = 0; _file_size = 0; _bytes_downloaded = 0; + _bytes_requested = 0; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/downloader/httpChannel.h b/panda/src/downloader/httpChannel.h index b42df1f3aa..50833354fe 100644 --- a/panda/src/downloader/httpChannel.h +++ b/panda/src/downloader/httpChannel.h @@ -119,6 +119,7 @@ PUBLISHED: bool download_to_ram(Ramfile *ramfile); INLINE size_t get_bytes_downloaded() const; + INLINE size_t get_bytes_requested() const; INLINE bool is_download_complete() const; private: @@ -222,6 +223,7 @@ private: size_t _file_size; size_t _bytes_downloaded; + size_t _bytes_requested; // These members are used to maintain the current state while // communicating with the server. We need to store everything in diff --git a/panda/src/downloader/httpClient.cxx b/panda/src/downloader/httpClient.cxx index 618fbad275..dd05946f8d 100644 --- a/panda/src/downloader/httpClient.cxx +++ b/panda/src/downloader/httpClient.cxx @@ -110,9 +110,11 @@ HTTPClient:: // Before we can free the context, we must remove the X509_STORE // pointer from it, so it won't be destroyed along with it (this // object is shared among all contexts). - nassertv(_ssl_ctx->cert_store == _x509_store); - _ssl_ctx->cert_store = NULL; - SSL_CTX_free(_ssl_ctx); + if (_ssl_ctx != (SSL_CTX *)NULL) { + nassertv(_ssl_ctx->cert_store == _x509_store); + _ssl_ctx->cert_store = NULL; + SSL_CTX_free(_ssl_ctx); + } // Free all of the expected server definitions. clear_expected_servers();