Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/network/kernel/qhostinfo.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    169169        QHostInfo hostInfo(id);
    170170        hostInfo.setError(QHostInfo::HostNotFound);
    171         hostInfo.setErrorString(QObject::tr("No host name given"));
     171        hostInfo.setErrorString(QCoreApplication::translate("QHostInfo", "No host name given"));
    172172        QScopedPointer<QHostInfoResult> result(new QHostInfoResult);
    173173        QObject::connect(result.data(), SIGNAL(resultsReady(QHostInfo)),
     
    244244#endif
    245245
    246     return QHostInfoAgent::fromName(name);
     246    QHostInfo hostInfo = QHostInfoAgent::fromName(name);
     247    QHostInfoLookupManager *manager = theHostInfoLookupManager();
     248    manager->cache.put(name, hostInfo);
     249    return hostInfo;
    247250}
    248251
     
    468471    resultEmitter.emitResultsReady(hostInfo);
    469472
     473    // now also iterate through the postponed ones
     474    {
     475        QMutexLocker locker(&manager->mutex);
     476        QMutableListIterator<QHostInfoRunnable*> iterator(manager->postponedLookups);
     477        while (iterator.hasNext()) {
     478            QHostInfoRunnable* postponed = iterator.next();
     479            if (toBeLookedUp == postponed->toBeLookedUp) {
     480                // we can now emit
     481                iterator.remove();
     482                hostInfo.setLookupId(postponed->id);
     483                postponed->resultEmitter.emitResultsReady(hostInfo);
     484            }
     485        }
     486    }
     487
    470488    manager->lookupFinished(this);
    471489
     
    485503
    486504    // don't qDeleteAll currentLookups, the QThreadPool has ownership
    487     qDeleteAll(postponedLookups);
    488     qDeleteAll(scheduledLookups);
    489     qDeleteAll(finishedLookups);
     505    clear();
     506}
     507
     508void QHostInfoLookupManager::clear()
     509{
     510    {
     511        QMutexLocker locker(&mutex);
     512        qDeleteAll(postponedLookups);
     513        qDeleteAll(scheduledLookups);
     514        qDeleteAll(finishedLookups);
     515        postponedLookups.clear();
     516        scheduledLookups.clear();
     517        finishedLookups.clear();
     518    }
     519
     520    threadPool.waitForDone();
     521    cache.clear();
    490522}
    491523
     
    579611
    580612    QMutexLocker locker(&this->mutex);
     613
     614    // is postponed? delete and return
     615    for (int i = 0; i < postponedLookups.length(); i++) {
     616        if (postponedLookups.at(i)->id == id) {
     617            delete postponedLookups.takeAt(i);
     618            return;
     619        }
     620    }
     621
     622    // is scheduled? delete and return
     623    for (int i = 0; i < scheduledLookups.length(); i++) {
     624        if (scheduledLookups.at(i)->id == id) {
     625            delete scheduledLookups.takeAt(i);
     626            return;
     627        }
     628    }
     629
    581630    if (!abortedLookups.contains(id))
    582631        abortedLookups.append(id);
     
    605654}
    606655
    607 // This function returns immediatly when we had a result in the cache, else it will later emit a signal
     656// This function returns immediately when we had a result in the cache, else it will later emit a signal
    608657QHostInfo qt_qhostinfo_lookup(const QString &name, QObject *receiver, const char *member, bool *valid, int *id)
    609658{
     
    631680    QHostInfoLookupManager* manager = theHostInfoLookupManager();
    632681    if (manager) {
    633         manager->cache.clear();
     682        manager->clear();
    634683    }
    635684}
Note: See TracChangeset for help on using the changeset viewer.