From 510272ce6c60fb5304db07f67b7ef67dee9e85f4 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Wed, 9 Mar 2016 18:59:33 +0200 Subject: [PATCH] QAbstractSocket: do not try to disable write notifications twice When canWriteNotication() is called and the socket successfully writes a chunk of data, then condition for disabling the notifications will be checked both in writeToSocket() and canWriteNotification(). Moving the code which handles notifications' state from canWriteNotification() to another branch in writeToSocket() eliminates a duplication and forces writeToSocket() to handle disabling the notifications in all cases. Change-Id: I6c14db552afe77b0cf1c9f5c511bafa127a45fe5 Reviewed-by: Oswald Buddenhagen Reviewed-by: Markus Goetz (Woboq GmbH) --- src/network/socket/qabstractsocket.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 0c7972d30f..a4ed5cc2df 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -788,12 +788,8 @@ bool QAbstractSocketPrivate::canWriteNotification() #if defined (QABSTRACTSOCKET_DEBUG) qDebug("QAbstractSocketPrivate::canWriteNotification() flushing"); #endif - bool dataWasWritten = writeToSocket(); - if (socketEngine && writeBuffer.isEmpty() && socketEngine->bytesToWrite() == 0) - socketEngine->setWriteNotificationEnabled(false); - - return dataWasWritten; + return writeToSocket(); } /*! \internal @@ -833,8 +829,12 @@ bool QAbstractSocketPrivate::writeToSocket() #endif // this covers the case when the buffer was empty, but we had to wait for the socket engine to finish - if (state == QAbstractSocket::ClosingState) + if (state == QAbstractSocket::ClosingState) { q->disconnectFromHost(); + } else { + if (socketEngine) + socketEngine->setWriteNotificationEnabled(false); + } return false; }