summaryrefslogtreecommitdiffstats
path: root/src/network/socket
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2016-03-26 15:28:19 +0200
committerAlex Trotsenko <alex1973tr@gmail.com>2016-08-11 06:53:27 +0000
commit04e676c03cf7c320bd5c5a21dfcb62613af711b6 (patch)
tree8610cc5ead76eae7ca144db6170c140404004a3d /src/network/socket
parent8ba384a5645aebbefe34b814828024d511171497 (diff)
QAbstractSocket: prevent waitForReadyRead() from early exit
According to documentation, waitForReadyRead() returns 'true' if the readyRead() signal is emitted and there is new data available for reading. Thus, waitForReadyRead() is being blocked in cycle until canReadNotification() will return 'true'. This patch adjusts canReadNotification() to return 'true' only when new data arrives on buffered socket that ensures waitForReadyRead() to succeed correctly. Change-Id: Ic38c4a4dd8ef9128f04b6c1d5f3d03068f6c9894 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network/socket')
-rw-r--r--src/network/socket/qabstractsocket.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp
index 88237dc416..ccb63f4716 100644
--- a/src/network/socket/qabstractsocket.cpp
+++ b/src/network/socket/qabstractsocket.cpp
@@ -687,10 +687,11 @@ bool QAbstractSocketPrivate::canReadNotification()
socketEngine->setReadNotificationEnabled(false);
// If buffered, read data from the socket into the read buffer
- qint64 newBytes = 0;
if (isBuffered) {
+ const qint64 oldBufferSize = buffer.size();
+
// Return if there is no space in the buffer
- if (readBufferMaxSize && buffer.size() >= readBufferMaxSize) {
+ if (readBufferMaxSize && oldBufferSize >= readBufferMaxSize) {
#if defined (QABSTRACTSOCKET_DEBUG)
qDebug("QAbstractSocketPrivate::canReadNotification() buffer is full");
#endif
@@ -699,7 +700,6 @@ bool QAbstractSocketPrivate::canReadNotification()
// If reading from the socket fails after getting a read
// notification, close the socket.
- newBytes = buffer.size();
if (!readFromSocket()) {
#if defined (QABSTRACTSOCKET_DEBUG)
qDebug("QAbstractSocketPrivate::canReadNotification() disconnecting socket");
@@ -707,7 +707,13 @@ bool QAbstractSocketPrivate::canReadNotification()
q->disconnectFromHost();
return false;
}
- newBytes = buffer.size() - newBytes;
+
+ // Return if there is no new data available.
+ if (buffer.size() == oldBufferSize) {
+ // If the socket is opened only for writing, return true
+ // to indicate that the data was discarded.
+ return !q->isReadable();
+ }
// If read buffer is full, disable the read socket notifier.
if (readBufferMaxSize && buffer.size() == readBufferMaxSize) {
@@ -715,9 +721,7 @@ bool QAbstractSocketPrivate::canReadNotification()
}
}
- // Only emit readyRead() if there is data available.
- if (newBytes > 0 || !isBuffered)
- emitReadyRead();
+ emitReadyRead();
// If we were closed as a result of the readyRead() signal,
// return.