Skip to content

Commit

Permalink
Revert "Fix the spurious socket notifications on OS X"
Browse files Browse the repository at this point in the history
This reverts commit b8e0f7c.
Needs a more testing.

Change-Id: Iff0b2741922cfa8f16fbc3f4ce0f83869d6cd8b6
Reviewed-by: Alex Trotsenko <alex1973tr@gmail.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
  • Loading branch information
Alex Trotsenko authored and Jani Heikkinen committed Oct 6, 2015
1 parent 44f323e commit da104e7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 42 deletions.
37 changes: 7 additions & 30 deletions src/platformsupport/cfsocketnotifier/qcfsocketnotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, &notifierEvent);
}
} else if (callbackType == kCFSocketWriteCallBack) {
if (socketInfo->writeNotifier && socketInfo->writeEnabled) {
socketInfo->writeEnabled = false;
if (socketInfo->writeNotifier)
QGuiApplication::sendEvent(socketInfo->writeNotifier, &notifierEvent);
}
}

if (cfSocketNotifier->maybeCancelWaitForMoreEvents)
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions src/platformsupport/cfsocketnotifier/qcfsocketnotifier_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, MacSocketInfo *> MacSocketHash;

Expand All @@ -84,7 +81,6 @@ class QCFSocketNotifier
void setMaybeCancelWaitForMoreEventsCallback(MaybeCancelWaitForMoreEventsFn callBack);
void registerSocketNotifier(QSocketNotifier *notifier);
void unregisterSocketNotifier(QSocketNotifier *notifier);
void enableSocketNotifiers();
void removeSocketNotifiers();

MacSocketHash macSockets;
Expand Down
11 changes: 4 additions & 7 deletions src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm
Original file line number Diff line number Diff line change
Expand Up @@ -845,13 +845,10 @@ void qt_mac_maybeCancelWaitForMoreEventsForwarder(QAbstractEventDispatcher *even
void QCocoaEventDispatcherPrivate::waitingObserverCallback(CFRunLoopObserverRef,
CFRunLoopActivity activity, void *info)
{
QCocoaEventDispatcher *dispatcher = static_cast<QCocoaEventDispatcher *>(info);
if (activity == kCFRunLoopBeforeWaiting) {
dispatcher->d_func()->cfSocketNotifier.enableSocketNotifiers();
emit dispatcher->aboutToBlock();
} else {
emit dispatcher->awake();
}
if (activity == kCFRunLoopBeforeWaiting)
emit static_cast<QCocoaEventDispatcher*>(info)->aboutToBlock();
else
emit static_cast<QCocoaEventDispatcher*>(info)->awake();
}

void QCocoaEventDispatcherPrivate::processPostedEvents()
Expand Down

0 comments on commit da104e7

Please sign in to comment.