support closing sockets explicitly

This commit is contained in:
David Rose 2003-04-21 18:09:58 +00:00
parent 1b9191f48e
commit 5e5abe8c50
11 changed files with 95 additions and 95 deletions

View File

@ -48,18 +48,6 @@ open(BioPtr *source) {
return *this; 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 // Function: OBioStream::Constructor
// Access: Public // Access: Public
@ -91,18 +79,6 @@ open(BioPtr *source) {
return *this; 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 // Function: BioStream::Constructor
// Access: Public // Access: Public
@ -133,15 +109,3 @@ open(BioPtr *source) {
_buf.open(source); _buf.open(source);
return *this; 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;
}

View File

@ -37,6 +37,17 @@ is_closed() {
return false; 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 // Function: OBioStream::is_closed
// Access: Public, Virtual // Access: Public, Virtual
@ -54,6 +65,17 @@ is_closed() {
return false; 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 // Function: BioStream::is_closed
// Access: Public, Virtual // Access: Public, Virtual
@ -71,4 +93,15 @@ is_closed() {
return false; 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 #endif // HAVE_SSL

View File

@ -42,9 +42,9 @@ public:
INLINE IBioStream(BioPtr *source); INLINE IBioStream(BioPtr *source);
INLINE IBioStream &open(BioPtr *source); INLINE IBioStream &open(BioPtr *source);
INLINE IBioStream &close();
virtual bool is_closed(); virtual bool is_closed();
virtual void close();
private: private:
BioStreamBuf _buf; BioStreamBuf _buf;
@ -65,9 +65,9 @@ public:
INLINE OBioStream(BioPtr *source); INLINE OBioStream(BioPtr *source);
INLINE OBioStream &open(BioPtr *source); INLINE OBioStream &open(BioPtr *source);
INLINE OBioStream &close();
virtual bool is_closed(); virtual bool is_closed();
virtual void close();
private: private:
BioStreamBuf _buf; BioStreamBuf _buf;
@ -84,9 +84,9 @@ public:
INLINE BioStream(BioPtr *source); INLINE BioStream(BioPtr *source);
INLINE BioStream &open(BioPtr *source); INLINE BioStream &open(BioPtr *source);
INLINE BioStream &close();
virtual bool is_closed(); virtual bool is_closed();
virtual void close();
private: private:
BioStreamBuf _buf; BioStreamBuf _buf;

View File

@ -194,39 +194,41 @@ underflow() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
size_t BioStreamBuf:: size_t BioStreamBuf::
write_chars(const char *start, size_t length) { 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); int write_count = BIO_write(*_source, start, length);
while (write_count != (int)(length - wrote_so_far)) { while (write_count != (int)(length - wrote_so_far)) {
if (write_count <= 0) { if (write_count <= 0) {
_is_closed = !BIO_should_retry(*_source); _is_closed = !BIO_should_retry(*_source);
if (_is_closed) { if (_is_closed) {
return wrote_so_far; return wrote_so_far;
} }
// Block on the underlying socket before we try to write some // Block on the underlying socket before we try to write some
// more. // more.
int fd = -1; int fd = -1;
BIO_get_fd(*_source, &fd); BIO_get_fd(*_source, &fd);
if (fd < 0) { if (fd < 0) {
downloader_cat.warning() downloader_cat.warning()
<< "socket BIO has no file descriptor.\n"; << "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 { } else {
downloader_cat.spam() // wrote some characters.
<< "waiting to write to BIO.\n"; wrote_so_far += write_count;
fd_set wset; }
FD_ZERO(&wset);
FD_SET(fd, &wset); // Try to write some more.
select(fd + 1, NULL, &wset, NULL, NULL); write_count = BIO_write(*_source, start + wrote_so_far, length - wrote_so_far);
}
} else {
// 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);
} }
return length; return length;

View File

@ -47,15 +47,3 @@ open(BioStreamPtr *source, HTTPChannel *doc) {
_buf.open_read(source, doc); _buf.open_read(source, doc);
return *this; 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;
}

View File

@ -37,4 +37,15 @@ is_closed() {
return false; 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 #endif // HAVE_SSL

View File

@ -45,9 +45,9 @@ public:
INLINE IChunkedStream(BioStreamPtr *source, HTTPChannel *doc); INLINE IChunkedStream(BioStreamPtr *source, HTTPChannel *doc);
INLINE IChunkedStream &open(BioStreamPtr *source, HTTPChannel *doc); INLINE IChunkedStream &open(BioStreamPtr *source, HTTPChannel *doc);
INLINE IChunkedStream &close();
virtual bool is_closed(); virtual bool is_closed();
virtual void close();
private: private:
ChunkedStreamBuf _buf; ChunkedStreamBuf _buf;

View File

@ -51,15 +51,3 @@ open(BioStreamPtr *source, HTTPChannel *doc,
_buf.open_read(source, doc, has_content_length, content_length); _buf.open_read(source, doc, has_content_length, content_length);
return *this; 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;
}

View File

@ -38,4 +38,15 @@ is_closed() {
return false; 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 #endif // HAVE_SSL

View File

@ -52,9 +52,9 @@ public:
INLINE IIdentityStream &open(BioStreamPtr *source, HTTPChannel *doc, INLINE IIdentityStream &open(BioStreamPtr *source, HTTPChannel *doc,
bool has_content_length, size_t content_length); bool has_content_length, size_t content_length);
INLINE IIdentityStream &close();
virtual bool is_closed(); virtual bool is_closed();
virtual void close();
private: private:
IdentityStreamBuf _buf; IdentityStreamBuf _buf;

View File

@ -48,6 +48,7 @@ PUBLISHED:
bool receive_datagram(Datagram &dg); bool receive_datagram(Datagram &dg);
virtual bool is_closed() = 0; virtual bool is_closed() = 0;
virtual void close() = 0;
private: private:
size_t _data_expected; size_t _data_expected;
@ -70,6 +71,7 @@ PUBLISHED:
bool send_datagram(const Datagram &dg); bool send_datagram(const Datagram &dg);
virtual bool is_closed() = 0; virtual bool is_closed() = 0;
virtual void close() = 0;
INLINE void set_collect_tcp(bool collect_tcp); INLINE void set_collect_tcp(bool collect_tcp);
INLINE bool get_collect_tcp() const; INLINE bool get_collect_tcp() const;
@ -99,6 +101,7 @@ PUBLISHED:
bool send_datagram(const Datagram &dg); bool send_datagram(const Datagram &dg);
virtual bool is_closed() = 0; virtual bool is_closed() = 0;
virtual void close() = 0;
INLINE void set_collect_tcp(bool collect_tcp); INLINE void set_collect_tcp(bool collect_tcp);
INLINE bool get_collect_tcp() const; INLINE bool get_collect_tcp() const;