summaryrefslogtreecommitdiffstats
path: root/src/network/socket/qabstractsocket.cpp
diff options
context:
space:
mode:
authorPeter Hartmann <peter.hartmann@nokia.com>2009-10-27 15:06:36 (GMT)
committerPeter Hartmann <peter.hartmann@nokia.com>2009-10-27 15:50:30 (GMT)
commit2c672ea518265496a0fc7c5de63ca7dda880dd85 (patch)
tree129936f2e10b7d7b5c944ef2265e3cef76d67254 /src/network/socket/qabstractsocket.cpp
parent2d0b29c312ddf422595ce9debb3678bb5c4d51b6 (diff)
downloadQt-2c672ea518265496a0fc7c5de63ca7dda880dd85.zip
Qt-2c672ea518265496a0fc7c5de63ca7dda880dd85.tar.gz
Qt-2c672ea518265496a0fc7c5de63ca7dda880dd85.tar.bz2
QAbstractSocket: insert timer to prevent timeout
This fixes a timeout that occurred on Mac with the gui event dispatcher: we were waiting for a write notification, but timed out when we were in closing state and still waiting for the socket engine to complete writing. Now we close the socket anyway after 2 seconds. Reviewed-by: Thiago Macieira
Diffstat (limited to 'src/network/socket/qabstractsocket.cpp')
-rw-r--r--src/network/socket/qabstractsocket.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp
index 955fee0..89a6e91 100644
--- a/src/network/socket/qabstractsocket.cpp
+++ b/src/network/socket/qabstractsocket.cpp
@@ -462,6 +462,7 @@ QAbstractSocketPrivate::QAbstractSocketPrivate()
isBuffered(false),
blockingTimeout(30000),
connectTimer(0),
+ disconnectTimer(0),
connectTimeElapsed(0),
hostLookupId(-1),
socketType(QAbstractSocket::UnknownSocketType),
@@ -497,9 +498,10 @@ void QAbstractSocketPrivate::resetSocketLayer()
socketEngine = 0;
cachedSocketDescriptor = -1;
}
- if (connectTimer) {
+ if (connectTimer)
connectTimer->stop();
- }
+ if (disconnectTimer)
+ disconnectTimer->stop();
}
/*! \internal
@@ -1094,6 +1096,15 @@ void QAbstractSocketPrivate::_q_abortConnectionAttempt()
}
}
+void QAbstractSocketPrivate::_q_forceDisconnect()
+{
+ Q_Q(QAbstractSocket);
+ if (socketEngine && socketEngine->isValid() && state == QAbstractSocket::ClosingState) {
+ socketEngine->close();
+ q->disconnectFromHost();
+ }
+}
+
/*! \internal
Reads data from the socket layer into the read buffer. Returns
@@ -2356,6 +2367,20 @@ void QAbstractSocket::disconnectFromHostImplementation()
// Wait for pending data to be written.
if (d->socketEngine && d->socketEngine->isValid() && (d->writeBuffer.size() > 0
|| d->socketEngine->bytesToWrite() > 0)) {
+ // hack: when we are waiting for the socket engine to write bytes (only
+ // possible when using Socks5 or HTTP socket engine), then close
+ // anyway after 2 seconds. This is to prevent a timeout on Mac, where we
+ // sometimes just did not get the write notifier from the underlying
+ // CFSocket and no progress was made.
+ if (d->writeBuffer.size() == 0 && d->socketEngine->bytesToWrite() > 0) {
+ if (!d->disconnectTimer) {
+ d->disconnectTimer = new QTimer(this);
+ connect(d->disconnectTimer, SIGNAL(timeout()), this,
+ SLOT(_q_forceDisconnect()), Qt::DirectConnection);
+ }
+ if (!d->disconnectTimer->isActive())
+ d->disconnectTimer->start(2000);
+ }
d->socketEngine->setWriteNotificationEnabled(true);
#if defined(QABSTRACTSOCKET_DEBUG)