From da104e7db04a5aeafb99a7b0ef3ab3cdd08da272 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Sat, 3 Oct 2015 17:02:36 +0300 Subject: Revert "Fix the spurious socket notifications on OS X" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b8e0f7cfc638a71770f44ada828ff2cf6d2ee201. Needs a more testing. Change-Id: Iff0b2741922cfa8f16fbc3f4ce0f83869d6cd8b6 Reviewed-by: Alex Trotsenko Reviewed-by: Tor Arne Vestbø --- .../cfsocketnotifier/qcfsocketnotifier.cpp | 37 ++++------------------ .../cfsocketnotifier/qcfsocketnotifier_p.h | 6 +--- .../platforms/cocoa/qcocoaeventdispatcher.mm | 11 +++---- 3 files changed, 12 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/platformsupport/cfsocketnotifier/qcfsocketnotifier.cpp b/src/platformsupport/cfsocketnotifier/qcfsocketnotifier.cpp index 91f7aeb7d0..2b5723d827 100644 --- a/src/platformsupport/cfsocketnotifier/qcfsocketnotifier.cpp +++ b/src/platformsupport/cfsocketnotifier/qcfsocketnotifier.cpp @@ -55,15 +55,11 @@ void qt_mac_socket_callback(CFSocketRef s, CFSocketCallBackType callbackType, CF // notifier is now gone. The upshot is we have to check the notifier // every time. if (callbackType == kCFSocketReadCallBack) { - if (socketInfo->readNotifier && socketInfo->readEnabled) { - socketInfo->readEnabled = false; + if (socketInfo->readNotifier) QGuiApplication::sendEvent(socketInfo->readNotifier, ¬ifierEvent); - } } else if (callbackType == kCFSocketWriteCallBack) { - if (socketInfo->writeNotifier && socketInfo->writeEnabled) { - socketInfo->writeEnabled = false; + if (socketInfo->writeNotifier) QGuiApplication::sendEvent(socketInfo->writeNotifier, ¬ifierEvent); - } } if (cfSocketNotifier->maybeCancelWaitForMoreEvents) @@ -154,8 +150,8 @@ void QCFSocketNotifier::registerSocketNotifier(QSocketNotifier *notifier) } CFOptionFlags flags = CFSocketGetSocketFlags(socketInfo->socket); - // QSocketNotifier doesn't close the socket upon destruction/invalidation - flags &= ~(kCFSocketCloseOnInvalidate | kCFSocketAutomaticallyReenableReadCallBack); + flags |= kCFSocketAutomaticallyReenableWriteCallBack; //QSocketNotifier stays enabled after a write + flags &= ~kCFSocketCloseOnInvalidate; //QSocketNotifier doesn't close the socket upon destruction/invalidation CFSocketSetSocketFlags(socketInfo->socket, flags); // Add CFSocket to runloop. @@ -175,14 +171,15 @@ void QCFSocketNotifier::registerSocketNotifier(QSocketNotifier *notifier) macSockets.insert(nativeSocket, socketInfo); } + // Increment read/write counters and select enable callbacks if necessary. if (type == QSocketNotifier::Read) { Q_ASSERT(socketInfo->readNotifier == 0); socketInfo->readNotifier = notifier; - socketInfo->readEnabled = false; + CFSocketEnableCallBacks(socketInfo->socket, kCFSocketReadCallBack); } else if (type == QSocketNotifier::Write) { Q_ASSERT(socketInfo->writeNotifier == 0); socketInfo->writeNotifier = notifier; - socketInfo->writeEnabled = false; + CFSocketEnableCallBacks(socketInfo->socket, kCFSocketWriteCallBack); } } @@ -215,12 +212,10 @@ void QCFSocketNotifier::unregisterSocketNotifier(QSocketNotifier *notifier) if (type == QSocketNotifier::Read) { Q_ASSERT(notifier == socketInfo->readNotifier); socketInfo->readNotifier = 0; - socketInfo->readEnabled = false; CFSocketDisableCallBacks(socketInfo->socket, kCFSocketReadCallBack); } else if (type == QSocketNotifier::Write) { Q_ASSERT(notifier == socketInfo->writeNotifier); socketInfo->writeNotifier = 0; - socketInfo->writeEnabled = false; CFSocketDisableCallBacks(socketInfo->socket, kCFSocketWriteCallBack); } @@ -237,24 +232,6 @@ void QCFSocketNotifier::unregisterSocketNotifier(QSocketNotifier *notifier) } } -void QCFSocketNotifier::enableSocketNotifiers() -{ - // Enable CFSockets in runloop. - for (MacSocketHash::ConstIterator it = macSockets.constBegin(); it != macSockets.constEnd(); ++it) { - MacSocketInfo *socketInfo = (*it); - if (CFSocketIsValid(socketInfo->socket)) { - if (socketInfo->readNotifier && !socketInfo->readEnabled) { - socketInfo->readEnabled = true; - CFSocketEnableCallBacks(socketInfo->socket, kCFSocketReadCallBack); - } - if (socketInfo->writeNotifier && !socketInfo->writeEnabled) { - socketInfo->writeEnabled = true; - CFSocketEnableCallBacks(socketInfo->socket, kCFSocketWriteCallBack); - } - } - } -} - void QCFSocketNotifier::removeSocketNotifiers() { // Remove CFSockets from the runloop. diff --git a/src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h b/src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h index 1d6dcf2885..af8122f753 100644 --- a/src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h +++ b/src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h @@ -53,14 +53,11 @@ QT_BEGIN_NAMESPACE struct MacSocketInfo { - MacSocketInfo() : socket(0), runloop(0), readNotifier(0), writeNotifier(0), - readEnabled(false), writeEnabled(false) {} + MacSocketInfo() : socket(0), runloop(0), readNotifier(0), writeNotifier(0) {} CFSocketRef socket; CFRunLoopSourceRef runloop; QObject *readNotifier; QObject *writeNotifier; - bool readEnabled; - bool writeEnabled; }; typedef QHash MacSocketHash; @@ -84,7 +81,6 @@ public: void setMaybeCancelWaitForMoreEventsCallback(MaybeCancelWaitForMoreEventsFn callBack); void registerSocketNotifier(QSocketNotifier *notifier); void unregisterSocketNotifier(QSocketNotifier *notifier); - void enableSocketNotifiers(); void removeSocketNotifiers(); MacSocketHash macSockets; diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index b443233d15..52b2e23345 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -845,13 +845,10 @@ QCocoaEventDispatcher::QCocoaEventDispatcher(QObject *parent) void QCocoaEventDispatcherPrivate::waitingObserverCallback(CFRunLoopObserverRef, CFRunLoopActivity activity, void *info) { - QCocoaEventDispatcher *dispatcher = static_cast(info); - if (activity == kCFRunLoopBeforeWaiting) { - dispatcher->d_func()->cfSocketNotifier.enableSocketNotifiers(); - emit dispatcher->aboutToBlock(); - } else { - emit dispatcher->awake(); - } + if (activity == kCFRunLoopBeforeWaiting) + emit static_cast(info)->aboutToBlock(); + else + emit static_cast(info)->awake(); } void QCocoaEventDispatcherPrivate::processPostedEvents() -- cgit v1.2.3