From b2ff0c2dc25f640a31fa170dd7cd8964bbcd51d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Thu, 22 Feb 2024 14:56:19 +0100 Subject: UDP: don't disable read notification unless we have a datagram The current logic that we will disable the read notification if we have any data at all doesn't make sense for users who use the receiveDatagram functionality, since they will not make any calls that trigger the read notifier to be re-enabled unless there is a datagram ready for us to hand back. Fixes: QTBUG-105871 Pick-to: 6.7 6.6 6.5 Change-Id: I0a1f1f8babb037d923d1124c2603b1cb466cfe18 Reviewed-by: Thiago Macieira --- src/network/socket/qabstractsocket.cpp | 8 ++++++-- src/network/socket/qabstractsocket_p.h | 1 + src/network/socket/qudpsocket.cpp | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src/network/socket') diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index e74f448987..7c48692155 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -637,11 +637,15 @@ bool QAbstractSocketPrivate::canReadNotification() return !q->isReadable(); } } else { - if (hasPendingData) { + const bool isUdpSocket = (socketType == QAbstractSocket::UdpSocket); + if (hasPendingData && (!isUdpSocket || hasPendingDatagram)) { socketEngine->setReadNotificationEnabled(false); return true; } - hasPendingData = true; + if (!isUdpSocket || socketEngine->hasPendingDatagrams()) { + hasPendingData = true; + hasPendingDatagram = isUdpSocket; + } } emitReadyRead(); diff --git a/src/network/socket/qabstractsocket_p.h b/src/network/socket/qabstractsocket_p.h index 98d74dcfd4..cc5f53179c 100644 --- a/src/network/socket/qabstractsocket_p.h +++ b/src/network/socket/qabstractsocket_p.h @@ -110,6 +110,7 @@ public: qint64 readBufferMaxSize = 0; bool isBuffered = false; bool hasPendingData = false; + bool hasPendingDatagram = false; QTimer *connectTimer = nullptr; diff --git a/src/network/socket/qudpsocket.cpp b/src/network/socket/qudpsocket.cpp index 2a7982057e..06bc6a4fd5 100644 --- a/src/network/socket/qudpsocket.cpp +++ b/src/network/socket/qudpsocket.cpp @@ -430,6 +430,7 @@ QNetworkDatagram QUdpSocket::receiveDatagram(qint64 maxSize) qint64 readBytes = d->socketEngine->readDatagram(result.d->data.data(), maxSize, &result.d->header, QAbstractSocketEngine::WantAll); d->hasPendingData = false; + d->hasPendingDatagram = false; d->socketEngine->setReadNotificationEnabled(true); if (readBytes < 0) { d->setErrorAndEmit(d->socketEngine->error(), d->socketEngine->errorString()); @@ -479,6 +480,7 @@ qint64 QUdpSocket::readDatagram(char *data, qint64 maxSize, QHostAddress *addres } d->hasPendingData = false; + d->hasPendingDatagram = false; d->socketEngine->setReadNotificationEnabled(true); if (readBytes < 0) { if (readBytes == -2) { -- cgit v1.2.3