summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-09-29 19:44:43 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-09-29 19:44:43 (GMT)
commitbea648fcd6bce4f0d7f19725f60e5b2b3ef0a340 (patch)
tree3b2c6931176633b99afcf40729e2923ecaa1e151
parent639c0b7c7fe05bd7a686d16d93f2720bd3bfad99 (diff)
downloadswift-contrib-bea648fcd6bce4f0d7f19725f60e5b2b3ef0a340.zip
swift-contrib-bea648fcd6bce4f0d7f19725f60e5b2b3ef0a340.tar.bz2
Temporarily reverting the previous patch, because of unforeseen problems.
Will recommit at a later time. This reverts commit 639c0b7c7fe05bd7a686d16d93f2720bd3bfad99.
-rw-r--r--Swiften/Network/BoostConnection.cpp12
-rw-r--r--Swiften/Network/BoostConnection.h1
2 files changed, 4 insertions, 9 deletions
diff --git a/Swiften/Network/BoostConnection.cpp b/Swiften/Network/BoostConnection.cpp
index 534ebdb..043743e 100644
--- a/Swiften/Network/BoostConnection.cpp
+++ b/Swiften/Network/BoostConnection.cpp
@@ -45,19 +45,19 @@ class SharedBuffer {
private:
boost::shared_ptr< std::vector<char, SafeAllocator<char> > > data_;
boost::asio::const_buffer buffer_;
};
// -----------------------------------------------------------------------------
BoostConnection::BoostConnection(boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) :
- eventLoop(eventLoop), ioService(ioService), socket_(*ioService), writing_(false), closeSocketAfterNextWrite_(false) {
+ eventLoop(eventLoop), ioService(ioService), socket_(*ioService), writing_(false) {
}
BoostConnection::~BoostConnection() {
}
void BoostConnection::listen() {
doRead();
}
@@ -69,33 +69,29 @@ 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().
- if (writing_) {
- closeSocketAfterNextWrite_ = true;
- } else {
- socket_.close();
+ while (writing_) {
+ Swift::sleep(10);
}
+ 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));
diff --git a/Swiften/Network/BoostConnection.h b/Swiften/Network/BoostConnection.h
index 2f0c7be..7d5ec60 100644
--- a/Swiften/Network/BoostConnection.h
+++ b/Swiften/Network/BoostConnection.h
@@ -57,12 +57,11 @@ namespace Swift {
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_;
- bool closeSocketAfterNextWrite_;
};
}