本文整理汇总了C++中czeroconfbrowser::ZeroconfService::GetHostname方法的典型用法代码示例。如果您正苦于以下问题:C++ ZeroconfService::GetHostname方法的具体用法?C++ ZeroconfService::GetHostname怎么用?C++ ZeroconfService::GetHostname使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类czeroconfbrowser::ZeroconfService
的用法示例。
在下文中一共展示了ZeroconfService::GetHostname方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doResolveService
bool CZeroconfBrowserMDNS::doResolveService(CZeroconfBrowser::ZeroconfService& fr_service, double f_timeout)
{
DNSServiceErrorType err;
DNSServiceRef sdRef = NULL;
//start resolving
m_resolving_service = fr_service;
m_resolved_event.Reset();
err = DNSServiceResolve(&sdRef, 0, kDNSServiceInterfaceIndexAny, fr_service.GetName(), fr_service.GetType(), fr_service.GetDomain(), ResolveCallback, this);
if( err != kDNSServiceErr_NoError )
{
if (sdRef)
DNSServiceRefDeallocate(sdRef);
CLog::Log(LOGERROR, "ZeroconfBrowserMDNS: DNSServiceResolve returned (error = %ld)", (int) err);
return false;
}
err = DNSServiceProcessResult(sdRef);
if (err != kDNSServiceErr_NoError)
CLog::Log(LOGERROR, "ZeroconfBrowserMDNS::doResolveService DNSServiceProcessResult returned (error = %ld)", (int) err);
#if defined(HAS_MDNS_EMBEDDED)
// when using the embedded mdns service the call to DNSServiceProcessResult
// above will not block until the resolving was finished - instead we have to
// wait for resolve to return or timeout
m_resolved_event.WaitMSec(f_timeout * 1000);
#endif //HAS_MDNS_EMBEDDED
fr_service = m_resolving_service;
if (sdRef)
DNSServiceRefDeallocate(sdRef);
// resolve the hostname
if (!fr_service.GetHostname().empty())
{
CStdString strIP;
// use mdns resolving
m_addrinfo_event.Reset();
sdRef = NULL;
err = DNSServiceGetAddrInfo(&sdRef, 0, kDNSServiceInterfaceIndexAny, kDNSServiceProtocol_IPv4, fr_service.GetHostname(), GetAddrInfoCallback, this);
if (err != kDNSServiceErr_NoError)
CLog::Log(LOGERROR, "ZeroconfBrowserMDNS: DNSServiceGetAddrInfo returned (error = %ld)", (int) err);
err = DNSServiceProcessResult(sdRef);
if (err != kDNSServiceErr_NoError)
CLog::Log(LOGERROR, "ZeroconfBrowserMDNS::doResolveService DNSServiceProcessResult returned (error = %ld)", (int) err);
#if defined(HAS_MDNS_EMBEDDED)
// when using the embedded mdns service the call to DNSServiceProcessResult
// above will not block until the resolving was finished - instead we have to
// wait for resolve to return or timeout
// give it 2 secs for resolving (resolving in mdns is cached and queued
// in timeslices off 1 sec
m_addrinfo_event.WaitMSec(2000);
#endif //HAS_MDNS_EMBEDDED
fr_service = m_resolving_service;
if (sdRef)
DNSServiceRefDeallocate(sdRef);
// fall back to our resolver
if (fr_service.GetIP().empty())
{
CLog::Log(LOGWARNING, "ZeroconfBrowserMDNS: Could not resolve hostname %s falling back to CDNSNameCache", fr_service.GetHostname().c_str());
if (CDNSNameCache::Lookup(fr_service.GetHostname(), strIP))
fr_service.SetIP(strIP);
else
CLog::Log(LOGERROR, "ZeroconfBrowserMDNS: Could not resolve hostname %s", fr_service.GetHostname().c_str());
}
}
return (!fr_service.GetIP().empty());
}