简介
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());