summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Network/BoostConnection.cpp')
-rw-r--r--Swiften/Network/BoostConnection.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/Swiften/Network/BoostConnection.cpp b/Swiften/Network/BoostConnection.cpp
index 534ebdb..7b997b4 100644
--- a/Swiften/Network/BoostConnection.cpp
+++ b/Swiften/Network/BoostConnection.cpp
@@ -69,33 +69,31 @@ void BoostConnection::connect(const HostAddressPort& addressPort) {
boost::bind(&BoostConnection::handleConnectFinished, shared_from_this(), boost::asio::placeholders::error));
}
void BoostConnection::disconnect() {
//MainEventLoop::removeEventsFromOwner(shared_from_this());
// 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().
+ boost::lock_guard<boost::mutex> lock(writeMutex_);
if (writing_) {
closeSocketAfterNextWrite_ = true;
} else {
socket_.close();
}
}
void BoostConnection::write(const SafeByteArray& data) {
boost::lock_guard<boost::mutex> lock(writeMutex_);
if (!writing_) {
writing_ = true;
doWrite(data);
- if (closeSocketAfterNextWrite_) {
- socket_.close();
- }
}
else {
append(writeQueue_, data);
}
}
void BoostConnection::doWrite(const SafeByteArray& data) {
boost::asio::async_write(socket_, SharedBuffer(data),
boost::bind(&BoostConnection::handleDataWritten, shared_from_this(), boost::asio::placeholders::error));
@@ -143,18 +141,21 @@ void BoostConnection::handleDataWritten(const boost::system::error_code& error)
eventLoop->postEvent(boost::bind(boost::ref(onDisconnected), boost::optional<Error>()), shared_from_this());
}
else {
eventLoop->postEvent(boost::bind(boost::ref(onDisconnected), WriteError), shared_from_this());
}
{
boost::lock_guard<boost::mutex> lock(writeMutex_);
if (writeQueue_.empty()) {
writing_ = false;
+ if (closeSocketAfterNextWrite_) {
+ socket_.close();
+ }
}
else {
doWrite(writeQueue_);
writeQueue_.clear();
}
}
}
HostAddressPort BoostConnection::getLocalAddress() const {