From 6542161d5c698d461a11f0e5ca6cc2a00d33a824 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Wed, 7 Oct 2015 16:49:47 +0300 Subject: Fix spurious socket notifications on OS X and iOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Core Foundation Framework forwards notifications about socket activity through a callback function which called from the run loop. The default behavior of Core Foundation is to automatically re-enable the read callback after each notification, and we explicitly enabled the same behavior for the write callback. With this behavior, if the client did multiple recv() calls in response to the first notification in a series of read notifications, the client would still get the QSocketNotifier notifications for the data that was already read. To get rid of these extra notifications, we disable automatically re-enabling the callbacks, and then manually enable them on each run loop pass. Task-number: QTBUG-48556 Change-Id: I0b060222b787f45600be0cb7da85d04aef415e57 Reviewed-by: Tor Arne Vestbø --- src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h') diff --git a/src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h b/src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h index af8122f753..9bccc1bf98 100644 --- a/src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h +++ b/src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h @@ -53,11 +53,14 @@ QT_BEGIN_NAMESPACE struct MacSocketInfo { - MacSocketInfo() : socket(0), runloop(0), readNotifier(0), writeNotifier(0) {} + MacSocketInfo() : socket(0), runloop(0), readNotifier(0), writeNotifier(0), + readEnabled(false), writeEnabled(false) {} CFSocketRef socket; CFRunLoopSourceRef runloop; QObject *readNotifier; QObject *writeNotifier; + bool readEnabled; + bool writeEnabled; }; typedef QHash MacSocketHash; @@ -83,9 +86,18 @@ public: void unregisterSocketNotifier(QSocketNotifier *notifier); void removeSocketNotifiers(); +private: + void destroyRunLoopObserver(); + + static void unregisterSocketInfo(MacSocketInfo *socketInfo); + static void enableSocketNotifiers(CFRunLoopObserverRef ref, CFRunLoopActivity activity, void *info); + MacSocketHash macSockets; QAbstractEventDispatcher *eventDispatcher; MaybeCancelWaitForMoreEventsFn maybeCancelWaitForMoreEvents; + CFRunLoopObserverRef enableNotifiersObserver; + + friend void qt_mac_socket_callback(CFSocketRef, CFSocketCallBackType, CFDataRef, const void *, void *); }; QT_END_NAMESPACE -- cgit v1.2.3