summaryrefslogtreecommitdiffstats
path: root/src/network/socket
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2015-02-11 20:02:07 +0200
committerAlex Trotsenko <alex1973tr@gmail.com>2015-09-10 12:50:58 +0000
commit378e26dd14df808a55471330400984841ef414d4 (patch)
tree2298a584f0472cb55fe96b280ed57ea12c25d5f3 /src/network/socket
parentd75505faccc9a86d9e76932ae022b660e01ad1a5 (diff)
QUdpSocket: avoid infinite read notifier blocking
There was a small amount of time between the last readDatagram() call and disabling a read notifier in case the socket had a pending datagram. If a new datagram arrived in this period, this qualified as absence of a datagram reader. Do not change the read notifier state because it is disabled on canReadNotification() entry and always enabled by the datagram reader. Thanks to Peter Seiderer, who investigated the same: "Querying hasPendingDatagrams() for enabling/disabling setReadNotificationEnabled() is racy (a new datagram could arrive after readDatagam() is called and before hasPendingDatagrams() is checked). But for unbuffered sockets the ReadNotification is already disabled before the readReady signal is emitted and should be re-enabled when calling read() or readDatagram() from the user." However, this patch does not completely solve the problem under Windows, as the socket notifier may emit spurious notifications. Task-number: QTBUG-46552 Change-Id: If7295d53ae2c788c39e86303502f38135c4d6180 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network/socket')
-rw-r--r--src/network/socket/qabstractsocket.cpp12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp
index c42b4f520c..d93150799c 100644
--- a/src/network/socket/qabstractsocket.cpp
+++ b/src/network/socket/qabstractsocket.cpp
@@ -739,15 +739,9 @@ bool QAbstractSocketPrivate::canReadNotification()
return true;
}
- if (socketEngine) {
- // turn the socket engine off if we've either:
- // - got pending datagrams
- // - reached the buffer size limit
- if (isBuffered)
- socketEngine->setReadNotificationEnabled(readBufferMaxSize == 0 || readBufferMaxSize > q->bytesAvailable());
- else if (socketType != QAbstractSocket::TcpSocket)
- socketEngine->setReadNotificationEnabled(!socketEngine->hasPendingDatagrams());
- }
+ // turn the socket engine off if we've reached the buffer size limit
+ if (socketEngine && isBuffered)
+ socketEngine->setReadNotificationEnabled(readBufferMaxSize == 0 || readBufferMaxSize > q->bytesAvailable());
// reset the read socket notifier state if we reentered inside the
// readyRead() connected slot.