path: root/src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h
diff options
authorAlex Trotsenko <>2015-10-01 17:41:07 +0300
committerJani Heikkinen <>2015-10-02 10:16:53 +0000
commitb8e0f7cfc638a71770f44ada828ff2cf6d2ee201 (patch)
tree5da2fd9c3225ea35333686149c5263d1e579f61e /src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h
parent7943d4f77c721da17b6be76cf1045d34654a8cc5 (diff)
Fix the spurious socket notifications on OS X
Core Foundation Framework forwards notifications about socket activity through a callback function which called from the run loop. Previous implementation sets kCFSocketReadCallBack, kCFSocketWriteCallBack to be automatically re-enabled after they are triggered. With these semantics, an application need not read all available data in response to a read notification: a single recv in response to each read notification is appropriate. If an application issues multiple recv calls in response to a single notification, it can receive spurious notifications. To solve this issue, this patch disables automatically reenabling callback feature. Now, callback gets called exactly once, and is not called again until manually re-enabled by calling CFSocketEnableCallBacks() just before entering to wait for the new events. Task-number: QTBUG-48556 Change-Id: Ia3393c2026230c7b3397cc614758dec1d432535f Reviewed-by: Morten Johan Sørvig <>
Diffstat (limited to 'src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h')
1 files changed, 5 insertions, 1 deletions
diff --git a/src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h b/src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h
index af8122f753..1d6dcf2885 100644
--- a/src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h
+++ b/src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h
@@ -53,11 +53,14 @@
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<int, MacSocketInfo *> MacSocketHash;
@@ -81,6 +84,7 @@ public:
void setMaybeCancelWaitForMoreEventsCallback(MaybeCancelWaitForMoreEventsFn callBack);
void registerSocketNotifier(QSocketNotifier *notifier);
void unregisterSocketNotifier(QSocketNotifier *notifier);
+ void enableSocketNotifiers();
void removeSocketNotifiers();
MacSocketHash macSockets;