Qt 4.8
qhostinfo.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qhostinfo.h"
43 #include "qhostinfo_p.h"
44 
45 #include "QtCore/qscopedpointer.h"
47 #include <qcoreapplication.h>
48 #include <qmetaobject.h>
49 #include <qstringlist.h>
50 #include <qthread.h>
51 #include <qurl.h>
52 #include <private/qnetworksession_p.h>
53 
54 #ifdef Q_OS_UNIX
55 # include <unistd.h>
56 #endif
57 
59 
60 //#define QHOSTINFO_DEBUG
61 
62 #ifndef Q_OS_SYMBIAN
63 Q_GLOBAL_STATIC(QHostInfoLookupManager, theHostInfoLookupManager)
64 #else
65 Q_GLOBAL_STATIC(QSymbianHostInfoLookupManager, theHostInfoLookupManager)
66 #endif
67 
126 
157  const char *member)
158 {
159 #if defined QHOSTINFO_DEBUG
160  qDebug("QHostInfo::lookupHost(\"%s\", %p, %s)",
161  name.toLatin1().constData(), receiver, member ? member + 1 : 0);
162 #endif
163 
165  qWarning("QHostInfo::lookupHost() called with no event dispatcher");
166  return -1;
167  }
168 
169  qRegisterMetaType<QHostInfo>("QHostInfo");
170 
171  int id = theIdCounter.fetchAndAddRelaxed(1); // generate unique ID
172 
173  if (name.isEmpty()) {
174  if (!receiver)
175  return -1;
176 
177  QHostInfo hostInfo(id);
179  hostInfo.setErrorString(QCoreApplication::translate("QHostInfo", "No host name given"));
181  QObject::connect(result.data(), SIGNAL(resultsReady(QHostInfo)),
182  receiver, member, Qt::QueuedConnection);
183  result.data()->emitResultsReady(hostInfo);
184  return id;
185  }
186 
187 #ifndef Q_OS_SYMBIAN
188  QHostInfoLookupManager *manager = theHostInfoLookupManager();
189 
190  if (manager) {
191  // the application is still alive
192  if (manager->cache.isEnabled()) {
193  // check cache first
194  bool valid = false;
195  QHostInfo info = manager->cache.get(name, &valid);
196  if (valid) {
197  if (!receiver)
198  return -1;
199 
200  info.setLookupId(id);
201  QHostInfoResult result;
202  QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection);
203  result.emitResultsReady(info);
204  return id;
205  }
206  }
207 
208  // cache is not enabled or it was not in the cache, do normal lookup
209  QHostInfoRunnable* runnable = new QHostInfoRunnable(name, id);
210  if (receiver)
211  QObject::connect(&runnable->resultEmitter, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection);
212  manager->scheduleLookup(runnable);
213  }
214 #else
215  QSymbianHostInfoLookupManager *manager = theHostInfoLookupManager();
216 
217  if (manager) {
218  // the application is still alive
219  if (manager->cache.isEnabled()) {
220  // check cache first
221  bool valid = false;
222  QHostInfo info = manager->cache.get(name, &valid);
223  if (valid) {
224  info.setLookupId(id);
225  QHostInfoResult result;
226  QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection);
227  result.emitResultsReady(info);
228  return id;
229  }
230  }
231 
232  // cache is not enabled or it was not in the cache, do normal lookup
233 #ifndef QT_NO_BEARERMANAGEMENT
234  QSharedPointer<QNetworkSession> networkSession;
235  QVariant v(receiver->property("_q_networksession"));
236  if (v.isValid())
237  networkSession = qvariant_cast< QSharedPointer<QNetworkSession> >(v);
238 #endif
239 
240  QSymbianHostResolver *symbianResolver = 0;
241  QT_TRAP_THROWING(symbianResolver = new QSymbianHostResolver(name, id, networkSession));
242  QObject::connect(&symbianResolver->resultEmitter, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection);
243  manager->scheduleLookup(symbianResolver);
244  }
245 #endif
246 
247  return id;
248 }
249 
256 {
257  theHostInfoLookupManager()->abortLookup(id);
258 }
259 
274 {
275 #if defined QHOSTINFO_DEBUG
276  qDebug("QHostInfo::fromName(\"%s\")",name.toLatin1().constData());
277 #endif
278 
279  QHostInfo hostInfo = QHostInfoAgent::fromName(name);
280  QAbstractHostInfoLookupManager* manager = theHostInfoLookupManager();
281  manager->cache.put(name, hostInfo);
282  return hostInfo;
283 }
284 
285 #ifndef QT_NO_BEARERMANAGEMENT
287 {
288 #if defined QHOSTINFO_DEBUG
289  qDebug("QHostInfoPrivate::fromName(\"%s\") with session %p",name.toLatin1().constData(), session.data());
290 #endif
291 
292  QHostInfo hostInfo = QHostInfoAgent::fromName(name, session);
293  QAbstractHostInfoLookupManager* manager = theHostInfoLookupManager();
294  manager->cache.put(name, hostInfo);
295  return hostInfo;
296 }
297 #endif
298 
299 #ifndef Q_OS_SYMBIAN
300 #ifndef QT_NO_BEARERMANAGEMENT
301 // This function has a special implementation for symbian right now in qhostinfo_symbian.cpp but not on other OS.
303 {
304  return QHostInfoAgent::fromName(hostName);
305 }
306 #endif
307 #endif
308 
309 
332  : d(new QHostInfoPrivate)
333 {
334  d->lookupId = id;
335 }
336 
341  : d(new QHostInfoPrivate(*other.d.data()))
342 {
343 }
344 
350 {
351  *d.data() = *other.d.data();
352  return *this;
353 }
354 
359 {
360 }
361 
373 {
374  return d->addrs;
375 }
376 
383 {
384  d->addrs = addresses;
385 }
386 
393 {
394  return d->hostName;
395 }
396 
403 {
404  d->hostName = hostName;
405 }
406 
414 {
415  return d->err;
416 }
417 
424 {
425  d->err = error;
426 }
427 
434 {
435  return d->lookupId;
436 }
437 
444 {
445  d->lookupId = id;
446 }
447 
455 {
456  return d->errorStr;
457 }
458 
466 {
467  d->errorStr = str;
468 }
469 
495 #ifndef Q_OS_SYMBIAN
496 QHostInfoRunnable::QHostInfoRunnable(QString hn, int i) : toBeLookedUp(hn), id(i)
497 {
498  setAutoDelete(true);
499 }
500 
501 // the QHostInfoLookupManager will at some point call this via a QThreadPool
503 {
504  QHostInfoLookupManager *manager = theHostInfoLookupManager();
505  // check aborted
506  if (manager->wasAborted(id)) {
507  manager->lookupFinished(this);
508  return;
509  }
510 
511  QHostInfo hostInfo;
512 
513  // QHostInfo::lookupHost already checks the cache. However we need to check
514  // it here too because it might have been cache saved by another QHostInfoRunnable
515  // in the meanwhile while this QHostInfoRunnable was scheduled but not running
516  if (manager->cache.isEnabled()) {
517  // check the cache first
518  bool valid = false;
519  hostInfo = manager->cache.get(toBeLookedUp, &valid);
520  if (!valid) {
521  // not in cache, we need to do the lookup and store the result in the cache
523  manager->cache.put(toBeLookedUp, hostInfo);
524  }
525  } else {
526  // cache is not enabled, just do the lookup and continue
528  }
529 
530  // check aborted again
531  if (manager->wasAborted(id)) {
532  manager->lookupFinished(this);
533  return;
534  }
535 
536  // signal emission
537  hostInfo.setLookupId(id);
539 
540  // now also iterate through the postponed ones
541  {
542  QMutexLocker locker(&manager->mutex);
543  QMutableListIterator<QHostInfoRunnable*> iterator(manager->postponedLookups);
544  while (iterator.hasNext()) {
545  QHostInfoRunnable* postponed = iterator.next();
546  if (toBeLookedUp == postponed->toBeLookedUp) {
547  // we can now emit
548  iterator.remove();
549  hostInfo.setLookupId(postponed->id);
550  postponed->resultEmitter.emitResultsReady(hostInfo);
551  delete postponed;
552  }
553  }
554  }
555 
556  manager->lookupFinished(this);
557 
558  // thread goes back to QThreadPool
559 }
560 
561 QHostInfoLookupManager::QHostInfoLookupManager() : mutex(QMutex::Recursive), wasDeleted(false)
562 {
565  threadPool.setMaxThreadCount(5); // do 5 DNS lookups in parallel
566 }
567 
569 {
570  wasDeleted = true;
571 
572  // don't qDeleteAll currentLookups, the QThreadPool has ownership
573  clear();
574 }
575 
577 {
578  {
579  QMutexLocker locker(&mutex);
586  }
587 
589  cache.clear();
590 }
591 
593 {
594  if (wasDeleted)
595  return;
596 
597  // goals of this function:
598  // - launch new lookups via the thread pool
599  // - make sure only one lookup per host/IP is in progress
600 
601  QMutexLocker locker(&mutex);
602 
603  if (!finishedLookups.isEmpty()) {
604  // remove ID from aborted if it is in there
605  for (int i = 0; i < finishedLookups.length(); i++) {
607  }
608 
610  }
611 
612  if (!postponedLookups.isEmpty()) {
613  // try to start the postponed ones
614 
615  QMutableListIterator<QHostInfoRunnable*> iterator(postponedLookups);
616  while (iterator.hasNext()) {
617  QHostInfoRunnable* postponed = iterator.next();
618 
619  // check if none of the postponed hostnames is currently running
620  bool alreadyRunning = false;
621  for (int i = 0; i < currentLookups.length(); i++) {
622  if (currentLookups.at(i)->toBeLookedUp == postponed->toBeLookedUp) {
623  alreadyRunning = true;
624  break;
625  }
626  }
627  if (!alreadyRunning) {
628  iterator.remove();
629  scheduledLookups.prepend(postponed); // prepend! we want to finish it ASAP
630  }
631  }
632  }
633 
634  if (!scheduledLookups.isEmpty()) {
635  // try to start the new ones
636  QMutableListIterator<QHostInfoRunnable*> iterator(scheduledLookups);
637  while (iterator.hasNext()) {
638  QHostInfoRunnable *scheduled = iterator.next();
639 
640  // check if a lookup for this host is already running, then postpone
641  for (int i = 0; i < currentLookups.size(); i++) {
642  if (currentLookups.at(i)->toBeLookedUp == scheduled->toBeLookedUp) {
643  iterator.remove();
644  postponedLookups.append(scheduled);
645  scheduled = 0;
646  break;
647  }
648  }
649 
650  if (scheduled && currentLookups.size() < threadPool.maxThreadCount()) {
651  // runnable now running in new thread, track this in currentLookups
652  threadPool.start(scheduled);
653  iterator.remove();
654  currentLookups.append(scheduled);
655  } else {
656  // was postponed, continue iterating
657  continue;
658  }
659  };
660  }
661 }
662 
663 // called by QHostInfo
665 {
666  if (wasDeleted)
667  return;
668 
669  QMutexLocker locker(&this->mutex);
671  work();
672 }
673 
674 // called by QHostInfo
676 {
677  if (wasDeleted)
678  return;
679 
680  QMutexLocker locker(&this->mutex);
681 
682  // is postponed? delete and return
683  for (int i = 0; i < postponedLookups.length(); i++) {
684  if (postponedLookups.at(i)->id == id) {
685  delete postponedLookups.takeAt(i);
686  return;
687  }
688  }
689 
690  // is scheduled? delete and return
691  for (int i = 0; i < scheduledLookups.length(); i++) {
692  if (scheduledLookups.at(i)->id == id) {
693  delete scheduledLookups.takeAt(i);
694  return;
695  }
696  }
697 
698  if (!abortedLookups.contains(id))
700 }
701 
702 // called from QHostInfoRunnable
704 {
705  if (wasDeleted)
706  return true;
707 
708  QMutexLocker locker(&this->mutex);
709  return abortedLookups.contains(id);
710 }
711 
712 // called from QHostInfoRunnable
714 {
715  if (wasDeleted)
716  return;
717 
718  QMutexLocker locker(&this->mutex);
721  work();
722 }
723 #endif
724 
725 // This function returns immediately when we had a result in the cache, else it will later emit a signal
726 QHostInfo qt_qhostinfo_lookup(const QString &name, QObject *receiver, const char *member, bool *valid, int *id)
727 {
728  *valid = false;
729  *id = -1;
730 
731  // check cache
732  QAbstractHostInfoLookupManager* manager = theHostInfoLookupManager();
733  if (manager && manager->cache.isEnabled()) {
734  QHostInfo info = manager->cache.get(name, valid);
735  if (*valid) {
736  return info;
737  }
738  }
739 
740  // was not in cache, trigger lookup
741  *id = QHostInfo::lookupHost(name, receiver, member);
742 
743  // return empty response, valid==false
744  return QHostInfo();
745 }
746 
748 {
749  QAbstractHostInfoLookupManager* manager = theHostInfoLookupManager();
750  if (manager) {
751  manager->clear();
752  }
753 }
754 
756 {
757  QAbstractHostInfoLookupManager* manager = theHostInfoLookupManager();
758  if (manager) {
759  manager->cache.setEnabled(e);
760  }
761 }
762 
763 // cache for 60 seconds
764 // cache 128 items
765 QHostInfoCache::QHostInfoCache() : max_age(60), enabled(true), cache(128)
766 {
767 #ifdef QT_QHOSTINFO_CACHE_DISABLED_BY_DEFAULT
768  enabled = false;
769 #endif
770 }
771 
773 {
774  return enabled;
775 }
776 
777 // this function is currently only used for the auto tests
778 // and not usable by public API
780 {
781  enabled = e;
782 }
783 
784 
786 {
787  QMutexLocker locker(&this->mutex);
788 
789  *valid = false;
790  if (cache.contains(name)) {
791  QHostInfoCacheElement *element = cache.object(name);
792  if (element->age.elapsed() < max_age*1000)
793  *valid = true;
794  return element->info;
795 
796  // FIXME idea:
797  // if too old but not expired, trigger a new lookup
798  // to freshen our cache
799  }
800 
801  return QHostInfo();
802 }
803 
805 {
806  // if the lookup failed, don't cache
807  if (info.error() != QHostInfo::NoError)
808  return;
809 
811  element->info = info;
812  element->age = QElapsedTimer();
813  element->age.start();
814 
815  QMutexLocker locker(&this->mutex);
816  cache.insert(name, element); // cache will take ownership
817 }
818 
820 {
821  QMutexLocker locker(&this->mutex);
822  cache.clear();
823 }
824 
826 {
827  return theHostInfoLookupManager();
828 }
829 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
int lookupId() const
Returns the ID of this lookup.
Definition: qhostinfo.cpp:433
static mach_timebase_info_data_t info
void qt_qhostinfo_clear_cache()
Definition: qhostinfo.cpp:747
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void emitResultsReady(const QHostInfo &info)
Definition: qhostinfo_p.h:89
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
QList< QHostAddress > addrs
Definition: qhostinfo_p.h:130
static QAbstractHostInfoLookupManager * globalInstance()
Definition: qhostinfo.cpp:825
bool isEnabled()
Definition: qhostinfo.cpp:772
T * data() const
Returns the value of the pointer referenced by this object.
void setErrorString(const QString &errorString)
Sets the human readable description of the error that occurred to str if the lookup failed...
Definition: qhostinfo.cpp:465
static QAbstractEventDispatcher * instance(QThread *thread=0)
Returns a pointer to the event dispatcher object for the specified thread.
#define SLOT(a)
Definition: qobjectdefs.h:226
static void abortHostLookup(int lookupId)
Aborts the host lookup with the ID id, as returned by lookupHost().
Definition: qhostinfo.cpp:255
void setAutoDelete(bool _autoDelete)
Enables auto-deletion if autoDelete is true; otherwise auto-deletion is disabled. ...
Definition: qrunnable.h:67
QThreadPool threadPool
Definition: qhostinfo_p.h:220
HostInfoError error() const
Returns the type of error that occurred if the host name lookup failed; otherwise returns NoError...
Definition: qhostinfo.cpp:413
The QString class provides a Unicode character string.
Definition: qstring.h:83
void put(const QString &name, const QHostInfo &info)
Definition: qhostinfo.cpp:804
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_BASIC_ATOMIC_INITIALIZER(a)
Definition: qbasicatomic.h:218
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
QList< QHostAddress > addresses() const
Returns the list of IP addresses associated with hostName().
Definition: qhostinfo.cpp:372
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
Q_CORE_EXPORT void qDebug(const char *,...)
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
Definition: qlist.h:796
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QCache< QString, QHostInfoCacheElement > cache
Definition: qhostinfo_p.h:159
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QList< int > abortedLookups
Definition: qhostinfo_p.h:218
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
QString toBeLookedUp
Definition: qhostinfo_p.h:171
void setHostName(const QString &name)
Sets the host name of this QHostInfo to hostName.
Definition: qhostinfo.cpp:402
void waitForDone()
Waits for each thread to exit and removes all threads from the thread pool.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void setAddresses(const QList< QHostAddress > &addresses)
Sets the list of addresses in this QHostInfo to addresses.
Definition: qhostinfo.cpp:382
QString hostName() const
Returns the name of the host whose IP addresses were looked up.
Definition: qhostinfo.cpp:392
const char * name
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void start(QRunnable *runnable, int priority=0)
Reserves a thread and uses it to run runnable, unless this thread will make the current thread count ...
Q_CORE_EXPORT void qWarning(const char *,...)
QHostInfo::HostInfoError err
Definition: qhostinfo_p.h:128
void Q_AUTOTEST_EXPORT qt_qhostinfo_enable_cache(bool e)
Definition: qhostinfo.cpp:755
static const char * data(const QByteArray &arr)
The QHostInfo class provides static functions for host name lookups.
Definition: qhostinfo.h:58
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
Definition: qobject.cpp:1458
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
void clear()
Removes all items from the list.
Definition: qlist.h:764
static QHostInfo fromName(const QString &hostName, QSharedPointer< QNetworkSession > networkSession)
Definition: qhostinfo.cpp:286
void setError(HostInfoError error)
Sets the error type of this QHostInfo to error.
Definition: qhostinfo.cpp:423
QList< QHostInfoRunnable * > currentLookups
Definition: qhostinfo_p.h:214
T * data() const
Returns the value of the pointer referenced by this object.
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
void scheduleLookup(QHostInfoRunnable *r)
Definition: qhostinfo.cpp:664
const int max_age
Definition: qhostinfo_p.h:145
void enqueue(const T &t)
Adds value t to the tail of the queue.
Definition: qqueue.h:60
QScopedPointer< QHostInfoPrivate > d
Definition: qhostinfo.h:95
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QHostInfo fromName(const QString &name)
Looks up the IP address(es) for the given host name.
Definition: qhostinfo.cpp:273
bool wasAborted(int id)
Definition: qhostinfo.cpp:703
void setEnabled(bool e)
Definition: qhostinfo.cpp:779
void abortLookup(int id)
Definition: qhostinfo.cpp:675
QHostInfoRunnable(QString hn, int i)
Definition: qhostinfo.cpp:496
static QThread * mainThread()
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
QHostInfo & operator=(const QHostInfo &d)
Assigns the data of the other object to this host info object, and returns a reference to it...
Definition: qhostinfo.cpp:349
~QHostInfo()
Destroys the host info object.
Definition: qhostinfo.cpp:358
int length() const
This function is identical to count().
Definition: qlist.h:281
QHostInfo(int lookupId=-1)
Constructs an empty host info object with lookup ID id.
Definition: qhostinfo.cpp:331
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static int lookupHost(const QString &name, QObject *receiver, const char *member)
Looks up the IP address(es) associated with host name name, and returns an ID for the lookup...
Definition: qhostinfo.cpp:156
int maxThreadCount
This property represents the maximum number of threads used by the thread pool.
Definition: qthreadpool.h:63
int fetchAndAddRelaxed(int valueToAdd)
void run()
Implement this pure virtual function in your subclass.
Definition: qhostinfo.cpp:502
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
QHostInfoResult resultEmitter
Definition: qhostinfo_p.h:173
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
T takeAt(int i)
Removes the item at index position i and returns it.
Definition: qlist.h:484
static QBasicAtomicInt theIdCounter
Definition: qhostinfo.cpp:125
QString errorString() const
If the lookup failed, this function returns a human readable description of the error; otherwise "Unk...
Definition: qhostinfo.cpp:454
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
HostInfoError
This enum describes the various errors that can occur when trying to resolve a host name...
Definition: qhostinfo.h:61
QList< QHostInfoRunnable * > finishedLookups
Definition: qhostinfo_p.h:217
static QHostInfo fromName(const QString &hostName)
void lookupFinished(QHostInfoRunnable *r)
Definition: qhostinfo.cpp:713
QQueue< QHostInfoRunnable * > scheduledLookups
Definition: qhostinfo_p.h:216
QHostInfo get(const QString &name, bool *valid)
Definition: qhostinfo.cpp:785
void setMaxThreadCount(int maxThreadCount)
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
QList< QHostInfoRunnable * > postponedLookups
Definition: qhostinfo_p.h:215
void start()
Starts this timer.
void setLookupId(int id)
Sets the ID of this lookup to id.
Definition: qhostinfo.cpp:443
#define enabled
QHostInfo qt_qhostinfo_lookup(const QString &name, QObject *receiver, const char *member, bool *valid, int *id)
Definition: qhostinfo.cpp:726
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770