From c2580661a20e30abaa23c61808d6370a575665c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sat, 15 Jan 2011 17:05:42 +0100 Subject: Wait to close the connection until pending writes are done. This hopefully fixes the uninterruptable hang on exit. diff --git a/Swiften/Network/BoostConnection.cpp b/Swiften/Network/BoostConnection.cpp index 7751535..2741bc8 100644 --- a/Swiften/Network/BoostConnection.cpp +++ b/Swiften/Network/BoostConnection.cpp @@ -14,6 +14,7 @@ #include "Swiften/Base/String.h" #include "Swiften/Base/ByteArray.h" #include "Swiften/Network/HostAddressPort.h" +#include "Swiften/Base/sleep.h" namespace Swift { @@ -63,6 +64,14 @@ void BoostConnection::connect(const HostAddressPort& addressPort) { 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(). + while (writing_) { + std::cerr << "Write in progress ... waiting to quit" << std::endl; + Swift::sleep(10); + } socket_.close(); } -- cgit v0.10.2-6-g49f6