Revert "Fix the spurious socket notifications on OS X"
This reverts commit b8e0f7cfc638a71770f44ada828ff2cf6d2ee201. Needs a more testing. Change-Id: Iff0b2741922cfa8f16fbc3f4ce0f83869d6cd8b6 Reviewed-by: Alex Trotsenko <alex1973tr@gmail.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
This commit is contained in:
parent
44f323e500
commit
da104e7db0
@ -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
|
// notifier is now gone. The upshot is we have to check the notifier
|
||||||
// every time.
|
// every time.
|
||||||
if (callbackType == kCFSocketReadCallBack) {
|
if (callbackType == kCFSocketReadCallBack) {
|
||||||
if (socketInfo->readNotifier && socketInfo->readEnabled) {
|
if (socketInfo->readNotifier)
|
||||||
socketInfo->readEnabled = false;
|
|
||||||
QGuiApplication::sendEvent(socketInfo->readNotifier, ¬ifierEvent);
|
QGuiApplication::sendEvent(socketInfo->readNotifier, ¬ifierEvent);
|
||||||
}
|
|
||||||
} else if (callbackType == kCFSocketWriteCallBack) {
|
} else if (callbackType == kCFSocketWriteCallBack) {
|
||||||
if (socketInfo->writeNotifier && socketInfo->writeEnabled) {
|
if (socketInfo->writeNotifier)
|
||||||
socketInfo->writeEnabled = false;
|
|
||||||
QGuiApplication::sendEvent(socketInfo->writeNotifier, ¬ifierEvent);
|
QGuiApplication::sendEvent(socketInfo->writeNotifier, ¬ifierEvent);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfSocketNotifier->maybeCancelWaitForMoreEvents)
|
if (cfSocketNotifier->maybeCancelWaitForMoreEvents)
|
||||||
@ -154,8 +150,8 @@ void QCFSocketNotifier::registerSocketNotifier(QSocketNotifier *notifier)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CFOptionFlags flags = CFSocketGetSocketFlags(socketInfo->socket);
|
CFOptionFlags flags = CFSocketGetSocketFlags(socketInfo->socket);
|
||||||
// QSocketNotifier doesn't close the socket upon destruction/invalidation
|
flags |= kCFSocketAutomaticallyReenableWriteCallBack; //QSocketNotifier stays enabled after a write
|
||||||
flags &= ~(kCFSocketCloseOnInvalidate | kCFSocketAutomaticallyReenableReadCallBack);
|
flags &= ~kCFSocketCloseOnInvalidate; //QSocketNotifier doesn't close the socket upon destruction/invalidation
|
||||||
CFSocketSetSocketFlags(socketInfo->socket, flags);
|
CFSocketSetSocketFlags(socketInfo->socket, flags);
|
||||||
|
|
||||||
// Add CFSocket to runloop.
|
// Add CFSocket to runloop.
|
||||||
@ -175,14 +171,15 @@ void QCFSocketNotifier::registerSocketNotifier(QSocketNotifier *notifier)
|
|||||||
macSockets.insert(nativeSocket, socketInfo);
|
macSockets.insert(nativeSocket, socketInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Increment read/write counters and select enable callbacks if necessary.
|
||||||
if (type == QSocketNotifier::Read) {
|
if (type == QSocketNotifier::Read) {
|
||||||
Q_ASSERT(socketInfo->readNotifier == 0);
|
Q_ASSERT(socketInfo->readNotifier == 0);
|
||||||
socketInfo->readNotifier = notifier;
|
socketInfo->readNotifier = notifier;
|
||||||
socketInfo->readEnabled = false;
|
CFSocketEnableCallBacks(socketInfo->socket, kCFSocketReadCallBack);
|
||||||
} else if (type == QSocketNotifier::Write) {
|
} else if (type == QSocketNotifier::Write) {
|
||||||
Q_ASSERT(socketInfo->writeNotifier == 0);
|
Q_ASSERT(socketInfo->writeNotifier == 0);
|
||||||
socketInfo->writeNotifier = notifier;
|
socketInfo->writeNotifier = notifier;
|
||||||
socketInfo->writeEnabled = false;
|
CFSocketEnableCallBacks(socketInfo->socket, kCFSocketWriteCallBack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,12 +212,10 @@ void QCFSocketNotifier::unregisterSocketNotifier(QSocketNotifier *notifier)
|
|||||||
if (type == QSocketNotifier::Read) {
|
if (type == QSocketNotifier::Read) {
|
||||||
Q_ASSERT(notifier == socketInfo->readNotifier);
|
Q_ASSERT(notifier == socketInfo->readNotifier);
|
||||||
socketInfo->readNotifier = 0;
|
socketInfo->readNotifier = 0;
|
||||||
socketInfo->readEnabled = false;
|
|
||||||
CFSocketDisableCallBacks(socketInfo->socket, kCFSocketReadCallBack);
|
CFSocketDisableCallBacks(socketInfo->socket, kCFSocketReadCallBack);
|
||||||
} else if (type == QSocketNotifier::Write) {
|
} else if (type == QSocketNotifier::Write) {
|
||||||
Q_ASSERT(notifier == socketInfo->writeNotifier);
|
Q_ASSERT(notifier == socketInfo->writeNotifier);
|
||||||
socketInfo->writeNotifier = 0;
|
socketInfo->writeNotifier = 0;
|
||||||
socketInfo->writeEnabled = false;
|
|
||||||
CFSocketDisableCallBacks(socketInfo->socket, kCFSocketWriteCallBack);
|
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()
|
void QCFSocketNotifier::removeSocketNotifiers()
|
||||||
{
|
{
|
||||||
// Remove CFSockets from the runloop.
|
// Remove CFSockets from the runloop.
|
||||||
|
@ -53,14 +53,11 @@
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
struct MacSocketInfo {
|
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;
|
CFSocketRef socket;
|
||||||
CFRunLoopSourceRef runloop;
|
CFRunLoopSourceRef runloop;
|
||||||
QObject *readNotifier;
|
QObject *readNotifier;
|
||||||
QObject *writeNotifier;
|
QObject *writeNotifier;
|
||||||
bool readEnabled;
|
|
||||||
bool writeEnabled;
|
|
||||||
};
|
};
|
||||||
typedef QHash<int, MacSocketInfo *> MacSocketHash;
|
typedef QHash<int, MacSocketInfo *> MacSocketHash;
|
||||||
|
|
||||||
@ -84,7 +81,6 @@ public:
|
|||||||
void setMaybeCancelWaitForMoreEventsCallback(MaybeCancelWaitForMoreEventsFn callBack);
|
void setMaybeCancelWaitForMoreEventsCallback(MaybeCancelWaitForMoreEventsFn callBack);
|
||||||
void registerSocketNotifier(QSocketNotifier *notifier);
|
void registerSocketNotifier(QSocketNotifier *notifier);
|
||||||
void unregisterSocketNotifier(QSocketNotifier *notifier);
|
void unregisterSocketNotifier(QSocketNotifier *notifier);
|
||||||
void enableSocketNotifiers();
|
|
||||||
void removeSocketNotifiers();
|
void removeSocketNotifiers();
|
||||||
|
|
||||||
MacSocketHash macSockets;
|
MacSocketHash macSockets;
|
||||||
|
@ -845,13 +845,10 @@ QCocoaEventDispatcher::QCocoaEventDispatcher(QObject *parent)
|
|||||||
void QCocoaEventDispatcherPrivate::waitingObserverCallback(CFRunLoopObserverRef,
|
void QCocoaEventDispatcherPrivate::waitingObserverCallback(CFRunLoopObserverRef,
|
||||||
CFRunLoopActivity activity, void *info)
|
CFRunLoopActivity activity, void *info)
|
||||||
{
|
{
|
||||||
QCocoaEventDispatcher *dispatcher = static_cast<QCocoaEventDispatcher *>(info);
|
if (activity == kCFRunLoopBeforeWaiting)
|
||||||
if (activity == kCFRunLoopBeforeWaiting) {
|
emit static_cast<QCocoaEventDispatcher*>(info)->aboutToBlock();
|
||||||
dispatcher->d_func()->cfSocketNotifier.enableSocketNotifiers();
|
else
|
||||||
emit dispatcher->aboutToBlock();
|
emit static_cast<QCocoaEventDispatcher*>(info)->awake();
|
||||||
} else {
|
|
||||||
emit dispatcher->awake();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QCocoaEventDispatcherPrivate::processPostedEvents()
|
void QCocoaEventDispatcherPrivate::processPostedEvents()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user