简介
QHostInfo表示主机信息,即主机名称
常用接口
static QHostInfo fromName(const QString &name);
QString hostName() const;
QList<QHostAddress> addresses() const;
结构
lookupHostImpl:用于发起查询主机地址
QHostInfoLookupManager
异步发起查询主机的管理器,在lookupHostImpl会用到
其中currentLookups, postponedLookups,threadPool在多线程中才会有
全局静态变量初始化
Q_GLOBAL_STATIC(QHostInfoLookupManager, theHostInfoLookupManager)
在管理器中的缓存中没有主机对应的主机信息时,会创建QHostInfoRunnable,调用scheduleLookup发起异步查询
在将新QHostInfoRunnable添加到scheduledLookups中,发起调度时
如果postponedLookups中的任务在currentLookups中不存在,会将postponedLookups中移动到scheduledLookups中
// Transfer any postponed lookups that aren't currently running to the scheduled list, keeping already-running lookups:
postponedLookups.erase(separate_if(postponedLookups.begin(),
postponedLookups.end(),
postponedLookups.begin(),
std::front_inserter(scheduledLookups), // prepend! we want to finish it ASAP
isAlreadyRunning).first,
postponedLookups.end());
如果当前正在处理列表currentLookups中已经包含提交的,会将scheduledLookups中已经在currentLookups存在的任务移动到postponedLookups中,在QHostInfoRunnable执行任务时(即run),执行完后会将postponedLookups中与当前任务相等的删除。
// Unschedule and postpone any that are currently running:
scheduledLookups.erase(separate_if(scheduledLookups.begin(),
scheduledLookups.end(),
std::back_inserter(postponedLookups),
scheduledLookups.begin(),
isAlreadyRunning).second,
scheduledLookups.end());

















