diff options
author | Martin Petersson <martin.petersson@nokia.com> | 2012-07-11 12:31:29 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-01 18:12:34 +0200 |
commit | b8453b6fe3552cdfe32c726f87bb30d897c679b0 (patch) | |
tree | 544227e592bda31eaf8ba266f33f7cadb6336a45 /src/network/socket/qabstractsocket.cpp | |
parent | e178b49522465becf1b0c56bff1974e6037ba9ec (diff) |
QtNetwork: Handle FD_CLOSE on Windows
We need to handle FD_CLOSE separately on Windows as this will be sent
only once. When we get FD_CLOSE we need to check if there is more data
available for reading. It there is this might indicate that there is
another FD_READ that we need to handle after the FD_CLOSE. So in this
case we will manually create another close event.
Task-number: QTBUG-19409
Task-number: QTBUG-25386
Change-Id: Ie19906bc3f64fb6a85a508a5ab12caac5d70ccdb
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
Diffstat (limited to 'src/network/socket/qabstractsocket.cpp')
-rw-r--r-- | src/network/socket/qabstractsocket.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 6b4e48fe62..7c91022759 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -746,6 +746,44 @@ bool QAbstractSocketPrivate::canReadNotification() /*! \internal + Slot connected to the close socket notifier. It's called when the + socket is closed. +*/ +void QAbstractSocketPrivate::canCloseNotification() +{ + Q_Q(QAbstractSocket); + +#if defined (QABSTRACTSOCKET_DEBUG) + qDebug("QAbstractSocketPrivate::canCloseNotification()"); +#endif + + qint64 newBytes = 0; + if (isBuffered) { + // Try to read to the buffer, if the read fail we can close the socket. + newBytes = buffer.size(); + if (!readFromSocket()) { + q->disconnectFromHost(); + return; + } + newBytes = buffer.size() - newBytes; + if (newBytes) { + // If there was still some data to be read from the socket + // then we could get another FD_READ. The disconnect will + // then occur when we read from the socket again and fail + // in canReadNotification or by the manually created + // closeNotification below. + emit q->readyRead(); + + QMetaObject::invokeMethod(socketEngine, "closeNotification", Qt::QueuedConnection); + } + } else if (socketType == QAbstractSocket::TcpSocket && socketEngine) { + emit q->readyRead(); + } +} + + +/*! \internal + Slot connected to the write socket notifier. It's called during a delayed connect or when the socket is ready for writing. */ |