diff --git a/panda/src/downloader/bioStream.I b/panda/src/downloader/bioStream.I index 29485a10c4..0cc9d881bc 100644 --- a/panda/src/downloader/bioStream.I +++ b/panda/src/downloader/bioStream.I @@ -48,18 +48,6 @@ open(BioPtr *source) { return *this; } -//////////////////////////////////////////////////////////////////// -// Function: IBioStream::close -// Access: Public -// Description: Resets the BioStream to empty, but does not actually -// close the source BIO unless owns_source was true. -//////////////////////////////////////////////////////////////////// -INLINE IBioStream &IBioStream:: -close() { - _buf.close(); - return *this; -} - //////////////////////////////////////////////////////////////////// // Function: OBioStream::Constructor // Access: Public @@ -91,18 +79,6 @@ open(BioPtr *source) { return *this; } -//////////////////////////////////////////////////////////////////// -// Function: OBioStream::close -// Access: Public -// Description: Resets the BioStream to empty, but does not actually -// close the source BIO unless owns_source was true. -//////////////////////////////////////////////////////////////////// -INLINE OBioStream &OBioStream:: -close() { - _buf.close(); - return *this; -} - //////////////////////////////////////////////////////////////////// // Function: BioStream::Constructor // Access: Public @@ -133,15 +109,3 @@ open(BioPtr *source) { _buf.open(source); return *this; } - -//////////////////////////////////////////////////////////////////// -// Function: BioStream::close -// Access: Public -// Description: Resets the BioStream to empty, but does not actually -// close the source BIO unless owns_source was true. -//////////////////////////////////////////////////////////////////// -INLINE BioStream &BioStream:: -close() { - _buf.close(); - return *this; -} diff --git a/panda/src/downloader/bioStream.cxx b/panda/src/downloader/bioStream.cxx index 77fcf39122..2e33e77e94 100644 --- a/panda/src/downloader/bioStream.cxx +++ b/panda/src/downloader/bioStream.cxx @@ -37,6 +37,17 @@ is_closed() { return false; } +//////////////////////////////////////////////////////////////////// +// Function: IBioStream::close +// Access: Public, Virtual +// Description: Resets the BioStream to empty, but does not actually +// close the source BIO unless owns_source was true. +//////////////////////////////////////////////////////////////////// +void IBioStream:: +close() { + _buf.close(); +} + //////////////////////////////////////////////////////////////////// // Function: OBioStream::is_closed // Access: Public, Virtual @@ -54,6 +65,17 @@ is_closed() { return false; } +//////////////////////////////////////////////////////////////////// +// Function: OBioStream::close +// Access: Public, Virtual +// Description: Resets the BioStream to empty, but does not actually +// close the source BIO unless owns_source was true. +//////////////////////////////////////////////////////////////////// +void OBioStream:: +close() { + _buf.close(); +} + //////////////////////////////////////////////////////////////////// // Function: BioStream::is_closed // Access: Public, Virtual @@ -71,4 +93,15 @@ is_closed() { return false; } +//////////////////////////////////////////////////////////////////// +// Function: BioStream::close +// Access: Public, Virtual +// Description: Resets the BioStream to empty, but does not actually +// close the source BIO unless owns_source was true. +//////////////////////////////////////////////////////////////////// +void BioStream:: +close() { + _buf.close(); +} + #endif // HAVE_SSL diff --git a/panda/src/downloader/bioStream.h b/panda/src/downloader/bioStream.h index b154651fd2..f7757429e6 100644 --- a/panda/src/downloader/bioStream.h +++ b/panda/src/downloader/bioStream.h @@ -42,9 +42,9 @@ public: INLINE IBioStream(BioPtr *source); INLINE IBioStream &open(BioPtr *source); - INLINE IBioStream &close(); virtual bool is_closed(); + virtual void close(); private: BioStreamBuf _buf; @@ -65,9 +65,9 @@ public: INLINE OBioStream(BioPtr *source); INLINE OBioStream &open(BioPtr *source); - INLINE OBioStream &close(); virtual bool is_closed(); + virtual void close(); private: BioStreamBuf _buf; @@ -84,9 +84,9 @@ public: INLINE BioStream(BioPtr *source); INLINE BioStream &open(BioPtr *source); - INLINE BioStream &close(); virtual bool is_closed(); + virtual void close(); private: BioStreamBuf _buf; diff --git a/panda/src/downloader/bioStreamBuf.cxx b/panda/src/downloader/bioStreamBuf.cxx index fb31a1b18b..d63953a69f 100644 --- a/panda/src/downloader/bioStreamBuf.cxx +++ b/panda/src/downloader/bioStreamBuf.cxx @@ -194,39 +194,41 @@ underflow() { //////////////////////////////////////////////////////////////////// size_t BioStreamBuf:: write_chars(const char *start, size_t length) { - size_t wrote_so_far = 0; + if (length != 0) { + size_t wrote_so_far = 0; - int write_count = BIO_write(*_source, start, length); - while (write_count != (int)(length - wrote_so_far)) { - if (write_count <= 0) { - _is_closed = !BIO_should_retry(*_source); - if (_is_closed) { - return wrote_so_far; - } - - // Block on the underlying socket before we try to write some - // more. - int fd = -1; - BIO_get_fd(*_source, &fd); - if (fd < 0) { - downloader_cat.warning() - << "socket BIO has no file descriptor.\n"; + int write_count = BIO_write(*_source, start, length); + while (write_count != (int)(length - wrote_so_far)) { + if (write_count <= 0) { + _is_closed = !BIO_should_retry(*_source); + if (_is_closed) { + return wrote_so_far; + } + + // Block on the underlying socket before we try to write some + // more. + int fd = -1; + BIO_get_fd(*_source, &fd); + if (fd < 0) { + downloader_cat.warning() + << "socket BIO has no file descriptor.\n"; + } else { + downloader_cat.spam() + << "waiting to write to BIO.\n"; + fd_set wset; + FD_ZERO(&wset); + FD_SET(fd, &wset); + select(fd + 1, NULL, &wset, NULL, NULL); + } + } else { - downloader_cat.spam() - << "waiting to write to BIO.\n"; - fd_set wset; - FD_ZERO(&wset); - FD_SET(fd, &wset); - select(fd + 1, NULL, &wset, NULL, NULL); - } - - } else { - // wrote some characters. - wrote_so_far += write_count; + // wrote some characters. + wrote_so_far += write_count; + } + + // Try to write some more. + write_count = BIO_write(*_source, start + wrote_so_far, length - wrote_so_far); } - - // Try to write some more. - write_count = BIO_write(*_source, start + wrote_so_far, length - wrote_so_far); } return length; diff --git a/panda/src/downloader/chunkedStream.I b/panda/src/downloader/chunkedStream.I index 63baa477ca..3356852b34 100644 --- a/panda/src/downloader/chunkedStream.I +++ b/panda/src/downloader/chunkedStream.I @@ -47,15 +47,3 @@ open(BioStreamPtr *source, HTTPChannel *doc) { _buf.open_read(source, doc); return *this; } - -//////////////////////////////////////////////////////////////////// -// Function: IChunkedStream::close -// Access: Public -// Description: Resets the ChunkedStream to empty, but does not actually -// close the source CHUNKED unless owns_source was true. -//////////////////////////////////////////////////////////////////// -INLINE IChunkedStream &IChunkedStream:: -close() { - _buf.close_read(); - return *this; -} diff --git a/panda/src/downloader/chunkedStream.cxx b/panda/src/downloader/chunkedStream.cxx index e5af7ba4ea..30ed5ac73f 100644 --- a/panda/src/downloader/chunkedStream.cxx +++ b/panda/src/downloader/chunkedStream.cxx @@ -37,4 +37,15 @@ is_closed() { return false; } +//////////////////////////////////////////////////////////////////// +// Function: IChunkedStream::close +// Access: Public, Virtual +// Description: Resets the ChunkedStream to empty, but does not actually +// close the source BIO unless owns_source was true. +//////////////////////////////////////////////////////////////////// +void IChunkedStream:: +close() { + _buf.close_read(); +} + #endif // HAVE_SSL diff --git a/panda/src/downloader/chunkedStream.h b/panda/src/downloader/chunkedStream.h index e656136d78..9f0d51cce7 100644 --- a/panda/src/downloader/chunkedStream.h +++ b/panda/src/downloader/chunkedStream.h @@ -45,9 +45,9 @@ public: INLINE IChunkedStream(BioStreamPtr *source, HTTPChannel *doc); INLINE IChunkedStream &open(BioStreamPtr *source, HTTPChannel *doc); - INLINE IChunkedStream &close(); virtual bool is_closed(); + virtual void close(); private: ChunkedStreamBuf _buf; diff --git a/panda/src/downloader/identityStream.I b/panda/src/downloader/identityStream.I index ded76fcd61..c48f8a77cc 100644 --- a/panda/src/downloader/identityStream.I +++ b/panda/src/downloader/identityStream.I @@ -51,15 +51,3 @@ open(BioStreamPtr *source, HTTPChannel *doc, _buf.open_read(source, doc, has_content_length, content_length); return *this; } - -//////////////////////////////////////////////////////////////////// -// Function: IIdentityStream::close -// Access: Public -// Description: Resets the IdentityStream to empty, but does not actually -// close the source IDENTITY unless owns_source was true. -//////////////////////////////////////////////////////////////////// -INLINE IIdentityStream &IIdentityStream:: -close() { - _buf.close_read(); - return *this; -} diff --git a/panda/src/downloader/identityStream.cxx b/panda/src/downloader/identityStream.cxx index e6bc3688fa..0d0131af34 100644 --- a/panda/src/downloader/identityStream.cxx +++ b/panda/src/downloader/identityStream.cxx @@ -38,4 +38,15 @@ is_closed() { return false; } +//////////////////////////////////////////////////////////////////// +// Function: IIdentityStream::close +// Access: Public, Virtual +// Description: Resets the IdentityStream to empty, but does not actually +// close the source BIO unless owns_source was true. +//////////////////////////////////////////////////////////////////// +void IIdentityStream:: +close() { + _buf.close_read(); +} + #endif // HAVE_SSL diff --git a/panda/src/downloader/identityStream.h b/panda/src/downloader/identityStream.h index 46c6af89d9..a5718d9356 100644 --- a/panda/src/downloader/identityStream.h +++ b/panda/src/downloader/identityStream.h @@ -52,9 +52,9 @@ public: INLINE IIdentityStream &open(BioStreamPtr *source, HTTPChannel *doc, bool has_content_length, size_t content_length); - INLINE IIdentityStream &close(); virtual bool is_closed(); + virtual void close(); private: IdentityStreamBuf _buf; diff --git a/panda/src/downloader/socketStream.h b/panda/src/downloader/socketStream.h index 699eb3afc1..d715420232 100644 --- a/panda/src/downloader/socketStream.h +++ b/panda/src/downloader/socketStream.h @@ -48,6 +48,7 @@ PUBLISHED: bool receive_datagram(Datagram &dg); virtual bool is_closed() = 0; + virtual void close() = 0; private: size_t _data_expected; @@ -70,6 +71,7 @@ PUBLISHED: bool send_datagram(const Datagram &dg); virtual bool is_closed() = 0; + virtual void close() = 0; INLINE void set_collect_tcp(bool collect_tcp); INLINE bool get_collect_tcp() const; @@ -99,6 +101,7 @@ PUBLISHED: bool send_datagram(const Datagram &dg); virtual bool is_closed() = 0; + virtual void close() = 0; INLINE void set_collect_tcp(bool collect_tcp); INLINE bool get_collect_tcp() const;