Changeset 161 for trunk/src


Ignore:
Timestamp:
Sep 7, 2009, 3:25:07 AM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: Fixed a number of socket notifier bugs in the event dispatcher code; this made the network classes actually work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/corelib/kernel/qeventdispatcher_pm.cpp

    r141 r161  
    497497{
    498498    QMutexLocker locker(&mutex);
    499     Q_ASSERT(instance);
     499    // it is possible that QEventDispatcherPM::unregisterTimers() is called
     500    // after detaching the last thread with detachThread() which means all
     501    // timers are already removed and the select thread is stopped and deleted.
     502    if (!instance)
     503        return false;
    500504
    501505    if (instance->timers.isEmpty())
     
    696700
    697701    do {
    698         while (!finish && sockets.isEmpty() && timers.isEmpty()) {
    699             if (!cancelWait)
    700                 cond.wait(&mutex);
    701             cancelWait = false;
    702         }
    703 
    704         if (finish)
    705             break;
    706 
    707702        // process pending socket operations
    708703        while (!pendingSockets.isEmpty()) {
     
    733728                    if (maxSockfd == p.sockfd) {
    734729                        // find the new hignest socket
    735                         if (hwnds.isEmpty()) {
    736                             maxSockfd = -1;
    737                         } else {
     730                        maxSockfd = -1;
     731                        if (!hwnds.isEmpty()) {
    738732                            for (Hwnds::const_iterator it = hwnds.constBegin();
    739733                                  it != hwnds.constEnd(); ++it) {
     
    755749        int nsel = 0;
    756750        if (maxSockfd >= 0) {
     751
    757752            mutex.unlock();
    758             nsel = ::select(maxSockfd + 1, &readS, &writeS, &exS, timeout);
     753            nsel = ::select(maxSockfd + 1, &, timeout);
    759754            if (nsel > 0) {
    760755                for (Hwnds::const_iterator it = hwnds.constBegin();
     
    764759                    switch (toSockType(it.key())) {
    765760                        case QSocketNotifier::Read:
    766                             isSet = FD_ISSET(sockfd, &readS); break;
     761                            isSet = FD_ISSET(sockfd, &); break;
    767762                        case QSocketNotifier::Write:
    768                             isSet = FD_ISSET(sockfd, &writeS); break;
     763                            isSet = FD_ISSET(sockfd, &); break;
    769764                        case QSocketNotifier::Exception:
    770                             isSet = FD_ISSET(sockfd, &exS); break;
     765                            isSet = FD_ISSET(sockfd, &); break;
    771766                    }
    772767                    if (isSet)
     
    778773            ulong msecs = timeout ?
    779774                timeout->tv_sec * 1000 + timeout->tv_usec / 1000 : ULONG_MAX;
     775
    780776            if (!cancelWait) {
    781                 if (cond.wait(&mutex, msecs))
    782                     nsel = -2; // avoid activation on when cancelled
    783             } else {
    784                 nsel = -2; // same as above
     777                if (!cond.wait(&mutex, msecs))
     778                    nsel = 0; // indicate timeout
    785779            }
    786780            cancelWait = false;
    787781        }
    788782
    789         if (nsel == 0 || (nsel == -1 && errno == EINTR)) {
     783        if (nsel == 0) {
    790784            // timeout, check if there are expired timers
    791785            activateTimers();
    792786        }
    793     } while(true);
     787
     788    } while(!finish);
    794789
    795790    mutex.unlock();
Note: See TracChangeset for help on using the changeset viewer.