diff options
| author | Tobias Markmann <tm@ayena.de> | 2011-09-29 08:25:23 (GMT) | 
|---|---|---|
| committer | Remko Tronçon <git@el-tramo.be> | 2011-09-29 18:58:40 (GMT) | 
| commit | 639c0b7c7fe05bd7a686d16d93f2720bd3bfad99 (patch) | |
| tree | 5ebcaf499403dbcbbd9316dc1e06acab717ce6b2 | |
| parent | 06a49ccc9554f2ce9e6d7b381543819590ea30ed (diff) | |
| download | swift-639c0b7c7fe05bd7a686d16d93f2720bd3bfad99.zip swift-639c0b7c7fe05bd7a686d16d93f2720bd3bfad99.tar.bz2 | |
In case of writing when calling disconnect() postpone socket.close() to when writing has finished.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
| -rw-r--r-- | Swiften/Network/BoostConnection.cpp | 12 | ||||
| -rw-r--r-- | Swiften/Network/BoostConnection.h | 1 | 
2 files changed, 9 insertions, 4 deletions
| diff --git a/Swiften/Network/BoostConnection.cpp b/Swiften/Network/BoostConnection.cpp index 043743e..534ebdb 100644 --- a/Swiften/Network/BoostConnection.cpp +++ b/Swiften/Network/BoostConnection.cpp @@ -51,7 +51,7 @@ class SharedBuffer {  // -----------------------------------------------------------------------------  BoostConnection::BoostConnection(boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : -		eventLoop(eventLoop), ioService(ioService), socket_(*ioService), writing_(false) { +	eventLoop(eventLoop), ioService(ioService), socket_(*ioService), writing_(false), closeSocketAfterNextWrite_(false) {  }  BoostConnection::~BoostConnection() { @@ -75,10 +75,11 @@ void BoostConnection::disconnect() {  	// Mac OS X apparently exhibits a problem where closing a socket during a write could potentially go into uninterruptable sleep.  	// See e.g. http://bugs.python.org/issue7401  	// We therefore wait until any pending write finishes, which hopefully should fix our hang on exit during close(). -	while (writing_) { -		Swift::sleep(10); +	if (writing_) { +		closeSocketAfterNextWrite_ = true; +	} else { +		socket_.close();  	} -	socket_.close();  }  void BoostConnection::write(const SafeByteArray& data) { @@ -86,6 +87,9 @@ void BoostConnection::write(const SafeByteArray& data) {  	if (!writing_) {  		writing_ = true;  		doWrite(data); +		if (closeSocketAfterNextWrite_) { +			socket_.close(); +		}  	}  	else {  		append(writeQueue_, data); diff --git a/Swiften/Network/BoostConnection.h b/Swiften/Network/BoostConnection.h index 7d5ec60..2f0c7be 100644 --- a/Swiften/Network/BoostConnection.h +++ b/Swiften/Network/BoostConnection.h @@ -63,5 +63,6 @@ namespace Swift {  			boost::mutex writeMutex_;  			bool writing_;  			SafeByteArray writeQueue_; +			bool closeSocketAfterNextWrite_;  	};  } | 
 Swift
 Swift