Przeglądaj źródła

fix lost message(s) at connection lost

David Rose 17 lat temu
rodzic
commit
730d3226f4

+ 3 - 3
panda/src/downloader/bioStream.cxx

@@ -26,7 +26,7 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool IBioStream::
 bool IBioStream::
 is_closed() {
 is_closed() {
-  if (_buf._is_closed) {
+  if (!_buf._read_open) {
     return true;
     return true;
   }
   }
   clear();
   clear();
@@ -54,7 +54,7 @@ close() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool OBioStream::
 bool OBioStream::
 is_closed() {
 is_closed() {
-  if (_buf._is_closed) {
+  if (!_buf._write_open) {
     return true;
     return true;
   }
   }
   clear();
   clear();
@@ -82,7 +82,7 @@ close() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool BioStream::
 bool BioStream::
 is_closed() {
 is_closed() {
-  if (_buf._is_closed) {
+  if (!_buf._read_open) {
     return true;
     return true;
   }
   }
   clear();
   clear();

+ 12 - 7
panda/src/downloader/bioStreamBuf.cxx

@@ -37,7 +37,8 @@ typedef int streamsize;
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 BioStreamBuf::
 BioStreamBuf::
 BioStreamBuf() {
 BioStreamBuf() {
-  _is_closed = false;
+  _read_open = false;
+  _write_open = false;
 
 
 #ifdef HAVE_IOSTREAM
 #ifdef HAVE_IOSTREAM
   _buffer = (char *)PANDA_MALLOC_ARRAY(8192);
   _buffer = (char *)PANDA_MALLOC_ARRAY(8192);
@@ -79,6 +80,8 @@ BioStreamBuf::
 void BioStreamBuf::
 void BioStreamBuf::
 open(BioPtr *source) {
 open(BioPtr *source) {
   _source = source;
   _source = source;
+  _read_open = true;
+  _write_open = true;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -90,6 +93,8 @@ void BioStreamBuf::
 close() {
 close() {
   sync();
   sync();
   _source.clear();
   _source.clear();
+  _read_open = false;
+  _write_open = false;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -188,8 +193,8 @@ underflow() {
         // which that never returns true, if the socket is closed by
         // which that never returns true, if the socket is closed by
         // the server.  But BIO_should_retry() *appears* to be
         // the server.  But BIO_should_retry() *appears* to be
         // reliable.
         // reliable.
-        _is_closed = !BIO_should_retry(*_source);
-        if (_is_closed) {
+        _read_open = BIO_should_retry(*_source);
+        if (!_read_open) {
           downloader_cat.info()
           downloader_cat.info()
             << "Lost connection to "
             << "Lost connection to "
             << _source->get_server_name() << ":" 
             << _source->get_server_name() << ":" 
@@ -255,10 +260,10 @@ write_chars(const char *start, size_t length) {
         // when the server is terminated, this seems to be the best
         // when the server is terminated, this seems to be the best
         // way of detecting that case on the client: a BIO write error
         // way of detecting that case on the client: a BIO write error
         // without a retry request
         // without a retry request
-        //_is_closed = !BIO_should_retry(*_source);
-        //_is_closed = BIO_eof(*_source);
-        _is_closed = !BIO_should_write(*_source);
-        if (_is_closed) {
+        //_write_open = BIO_should_retry(*_source);
+        //_write_open = !BIO_eof(*_source);
+        _write_open = BIO_should_write(*_source);
+        if (!_write_open) {
           return wrote_so_far;
           return wrote_so_far;
         }
         }
         
         

+ 2 - 1
panda/src/downloader/bioStreamBuf.h

@@ -47,7 +47,8 @@ private:
   size_t write_chars(const char *start, size_t length);
   size_t write_chars(const char *start, size_t length);
 
 
   PT(BioPtr) _source;
   PT(BioPtr) _source;
-  bool _is_closed;
+  bool _read_open;
+  bool _write_open;
   char *_buffer;
   char *_buffer;
 
 
   friend class IBioStream;
   friend class IBioStream;