summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swiften/Network/BoostConnection.cpp12
-rw-r--r--Swiften/Network/BoostConnection.h1
2 files changed, 9 insertions, 4 deletions
diff --git a/Swiften/Network/BoostConnection.cpp b/Swiften/Network/BoostConnection.cpp
index b6b2d9d..1d4bd32 100644
--- a/Swiften/Network/BoostConnection.cpp
+++ b/Swiften/Network/BoostConnection.cpp
@@ -73,23 +73,28 @@ 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_.shutdown();
- socket_.close();
+ closeSocket();
}
}
+void BoostConnection::closeSocket() {
+ boost::system::error_code errorCode;
+ socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, errorCode);
+ socket_.close();
+}
+
void BoostConnection::write(const SafeByteArray& data) {
boost::lock_guard<boost::mutex> lock(writeMutex_);
if (!writing_) {
writing_ = true;
doWrite(data);
}
else {
append(writeQueue_, data);
}
@@ -143,20 +148,19 @@ void BoostConnection::handleDataWritten(const boost::system::error_code& error)
}
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_.shutdown();
- socket_.close();
+ closeSocket();
}
}
else {
doWrite(writeQueue_);
writeQueue_.clear();
}
}
}
diff --git a/Swiften/Network/BoostConnection.h b/Swiften/Network/BoostConnection.h
index 2f0c7be..0e29c54 100644
--- a/Swiften/Network/BoostConnection.h
+++ b/Swiften/Network/BoostConnection.h
@@ -48,18 +48,19 @@ namespace Swift {
private:
BoostConnection(boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop);
void handleConnectFinished(const boost::system::error_code& error);
void handleSocketRead(const boost::system::error_code& error, size_t bytesTransferred);
void handleDataWritten(const boost::system::error_code& error);
void doRead();
void doWrite(const SafeByteArray& data);
+ void closeSocket();
private:
EventLoop* eventLoop;
boost::shared_ptr<boost::asio::io_service> ioService;
boost::asio::ip::tcp::socket socket_;
boost::shared_ptr<SafeByteArray> readBuffer_;
boost::mutex writeMutex_;
bool writing_;
SafeByteArray writeQueue_;