使用kDNSServiceFlagsShareConnection共享DNSServiceRef会停止我的程序

我正在使用Bonjour的dns-sd api建立一个客户端。我注意到有一个名为kDNSServiceFlagsShareConnection的标志,它用于共享一个DNSServiceRef的连接。 Apple网站说   为了提高效率,执行许多并发操作的客户端可能希望使用与后台守护程序的单个Unix域套接字连接,而不是为每个独立操作使用单独的连接。要使用此模式,客户端首先调用DNSServiceCreateConnection(& MainRef)来初始化主DNSServiceRef。对于要共享同一连接的每个后续操作,客户端复制MainRef,然后传递该副本的地址,设置ShareConnection标志以告知库该DNSServiceRef不是典型的未初始化的DNSServiceRef;它是现有DNSServiceRef的副本,其重新连接信息应该被重用。 甚至有一个例子展示了如何使用旗帜。我遇到的问题是当我运行程序时,每当我调用带有标志的函数时,它就像等待某事一样。这是代码:
DNSServiceErrorType error;
DNSServiceRef MainRef, BrowseRef;

error = DNSServiceCreateConnection(&MainRef);
BrowseRef = MainRef;
//I'm omitting when I check for errors

error = DNSServiceBrowse(&MainRef, kDNSServiceFlagsShareConnection, 0, "_http._tcp", "local", browse_reply, NULL); 
// After this call the program stays waiting for I don't know what

//I'm omitting when I check for errors
error = DNSServiceBrowse(&BrowseRef, kDNSServiceFlagsShareConnection, 0, "_http._tcp", "local", browse_reply, NULL);
//I'm omitting when i check for errors
DNSServiceRefDeallocate(BrowseRef); // Terminate the browse operation
DNSServiceRefDeallocate(MainRef); // Terminate the shared connection
有任何想法吗?想法?建议?     
已邀请:
由于存在相互矛盾的答案,我挖出了源 - 我的注释。
// If sharing...
if (flags & kDNSServiceFlagsShareConnection)
{
    // There must be something to share (can't use this on the first call)
    if (!*ref)
    {
        return kDNSServiceErr_BadParam;
    }
    // Ref must look valid (specifically, ref->fd)
    if (!DNSServiceRefValid(*ref) || 
    // Most operations cannot be shared.
          ((*ref)->op != connection_request &&
           (*ref)->op != connection_delegate_request) ||
    // When sharing, pass the ref from the original call.
        (*ref)->primary)
    {
         return kDNSServiceErr_BadReference;
    }
primary
fiels在别处解释:
// When using kDNSServiceFlagsShareConnection, there is one primary _DNSServiceOp_t, and zero or more subordinates
// For the primary, the 'next' field points to the first subordinate, and its 'next' field points to the next, and so on.
// For the primary, the 'primary' field is NULL; for subordinates the 'primary' field points back to the associated primary
这个问题的问题是
DNSServiceBrowse
映射到
ref->op==browse_request
,导致
kDNSServiceErr_BadReference
。 看起来
kDNSServiceFlagsShareConnection
是半实现的,因为我也看到了它工作的情况 - 这个源是通过追溯它找不到的时候找到的。     
遗憾的是,不能共享用于浏览和解析的服务引用。有关
kDNSServiceFlagsShareConnection
-flag的信息,请参阅Bonjour文档中的注释。由于你只浏览了两次,我只想让它们有单独的service-refs。 因此,
DNSServiceBrowse()
DNSServiceResolve()
都需要一个未分配的service-ref作为第一个参数。 我无法解释为什么你的程序会窒息。您示例中的第一个
DNSServiceBrowse()
调用应立即返回错误代码。     
虽然是一个老问题,但它应该帮助人们现在四处寻找答案。 vidtige的答案是不正确的,只要你传递'kDNSServiceFlagsShareConnection'标志和参数,就可以为任何操作共享。以下示例 -
    m_dnsrefsearch = m_dnsservice;
    DNSServiceErrorType mdnserr = DNSServiceBrowse(&m_dnsrefsearch,kDNSServiceFlagsShareConnection,0,
        "_workstation._tcp",NULL,
        DNSServiceBrowseReplyCallback,NULL);
参考 - http://osxr.org/android/source/external/mdnsresponder/mDNSShared/dns_sd.h#0267     

要回复问题请先登录注册