void QCFSocketNotifier::removeSocketNotifiers() { // Remove CFSockets from the runloop. for (MacSocketHash::ConstIterator it = macSockets.constBegin(); it != macSockets.constEnd(); ++it) { MacSocketInfo *socketInfo = (*it); if (CFSocketIsValid(socketInfo->socket)) { qt_mac_remove_socket_from_runloop(socketInfo->socket, socketInfo->runloop); CFRunLoopSourceInvalidate(socketInfo->runloop); CFRelease(socketInfo->runloop); CFSocketInvalidate(socketInfo->socket); CFRelease(socketInfo->socket); } } }
/* Unregister QSocketNotifer. The CFSocket correspoding to this notifier is removed from the runloop of this is the last notifier that users that CFSocket. */ void QEventDispatcherMac::unregisterSocketNotifier(QSocketNotifier *notifier) { Q_ASSERT(notifier); int nativeSocket = notifier->socket(); int type = notifier->type(); #ifndef QT_NO_DEBUG if (nativeSocket < 0 || nativeSocket > FD_SETSIZE) { qWarning("QSocketNotifier: Internal error"); return; } else if (notifier->thread() != thread() || thread() != QThread::currentThread()) { qWarning("QSocketNotifier: socket notifiers cannot be disabled from another thread"); return; } #endif Q_D(QEventDispatcherMac); QEventDispatcherUNIX::unregisterSocketNotifier(notifier); if (type == QSocketNotifier::Exception) { qWarning("QSocketNotifier::Exception is not supported on Mac OS X"); return; } MacSocketInfo *socketInfo = d->macSockets.value(nativeSocket); if (!socketInfo) { qWarning("QEventDispatcherMac::unregisterSocketNotifier: Tried to unregister a not registered notifier"); return; } // Decrement read/write counters and disable callbacks if necessary. if (type == QSocketNotifier::Read) { if (--socketInfo->read == 0) CFSocketDisableCallBacks(socketInfo->socket, kCFSocketReadCallBack); } else if (type == QSocketNotifier::Write) { if (--socketInfo->write == 0) CFSocketDisableCallBacks(socketInfo->socket, kCFSocketWriteCallBack); } // Remove CFSocket from runloop if this was the last QSocketNotifier. if (socketInfo->read <= 0 && socketInfo->write <= 0) { if (CFSocketIsValid(socketInfo->socket)) qt_mac_remove_socket_from_runloop(socketInfo->socket, socketInfo->runloop); CFRunLoopSourceInvalidate(socketInfo->runloop); CFRelease(socketInfo->runloop); CFSocketInvalidate(socketInfo->socket); CFRelease(socketInfo->socket); delete socketInfo; d->macSockets.remove(nativeSocket); } }
QEventDispatcherMac::~QEventDispatcherMac() { Q_D(QEventDispatcherMac); //timer cleanup d->zero_timer_count = 0; if(d->macTimerList) { for (int i = 0; i < d->macTimerList->size(); ++i) { const MacTimerInfo &t = d->macTimerList->at(i); if (t.mac_timer) { RemoveEventLoopTimer(t.mac_timer); if (t.pending) { EventComparatorUPP fnc = NewEventComparatorUPP(find_timer_event); FlushSpecificEventsFromQueue(GetMainEventQueue(), fnc, (void *)&t); DisposeEventComparatorUPP(fnc); } } } delete d->macTimerList; d->macTimerList = 0; } if(timerUPP) { DisposeEventLoopTimerUPP(timerUPP); timerUPP = 0; } // Remove CFSockets from the runloop. for (MacSocketHash::ConstIterator it = d->macSockets.constBegin(); it != d->macSockets.constEnd(); ++it) { MacSocketInfo *socketInfo = (*it); if (CFSocketIsValid(socketInfo->socket)) { qt_mac_remove_socket_from_runloop(socketInfo->socket, socketInfo->runloop); CFRunLoopSourceInvalidate(socketInfo->runloop); CFRelease(socketInfo->runloop); CFSocketInvalidate(socketInfo->socket); CFRelease(socketInfo->socket); } } CFRunLoopRemoveSource(runLoopForCarbonLoop(GetMainEventLoop()), d->postedEventsSource, kCFRunLoopCommonModes); CFRelease(d->postedEventsSource); d->postedEventsSource = 0; }