本文整理匯總了C++中DNSServiceRefSockFD函數的典型用法代碼示例。如果您正苦於以下問題:C++ DNSServiceRefSockFD函數的具體用法?C++ DNSServiceRefSockFD怎麽用?C++ DNSServiceRefSockFD使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了DNSServiceRefSockFD函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: FD_ZERO
ConnectionError Client::recv( int timeout )
{
if( m_connection && m_connection->state() == StateConnected )
return ClientBase::recv( timeout );
else
{
if( !m_currentRef )
return ConnNoError;
struct timeval tv;
fd_set fds;
FD_ZERO( &fds );
// the following causes a C4127 warning in VC++ Express 2008 and possibly other versions.
// however, the reason for the warning can't be fixed in gloox.
FD_SET( DNSServiceRefSockFD( m_currentRef ), &fds );
tv.tv_sec = timeout / 1000000;
tv.tv_usec = timeout % 1000000;
if( select( FD_SETSIZE, &fds, 0, 0, timeout == -1 ? 0 : &tv ) > 0 )
{
if( FD_ISSET( DNSServiceRefSockFD( m_currentRef ), &fds ) != 0 )
DNSServiceProcessResult( m_currentRef );
}
return ConnNoError;
}
}
示例2: DNSServiceEnumerateDomains
OSStatus
CConfigPropertySheet::SetupBrowsing()
{
OSStatus err;
// Start browsing for browse domains
err = DNSServiceEnumerateDomains( &m_browseDomainsRef, kDNSServiceFlagsBrowseDomains, 0, BrowseDomainsReply, this );
require_noerr( err, exit );
err = WSAAsyncSelect( DNSServiceRefSockFD( m_browseDomainsRef ), m_hWnd, WM_DATAREADY, FD_READ|FD_CLOSE );
require_noerr( err, exit );
// Start browsing for registration domains
err = DNSServiceEnumerateDomains( &m_regDomainsRef, kDNSServiceFlagsRegistrationDomains, 0, RegDomainsReply, this );
require_noerr( err, exit );
err = WSAAsyncSelect( DNSServiceRefSockFD( m_regDomainsRef ), m_hWnd, WM_DATAREADY, FD_READ|FD_CLOSE );
require_noerr( err, exit );
exit:
if ( err )
{
TearDownBrowsing();
}
return err;
}
示例3: WSAAsyncSelect
OSStatus
CConfigPropertySheet::TearDownBrowsing()
{
OSStatus err = kNoErr;
if ( m_browseDomainsRef )
{
err = WSAAsyncSelect( DNSServiceRefSockFD( m_browseDomainsRef ), m_hWnd, 0, 0 );
check_noerr( err );
DNSServiceRefDeallocate( m_browseDomainsRef );
m_browseDomainsRef = NULL;
}
if ( m_regDomainsRef )
{
err = WSAAsyncSelect( DNSServiceRefSockFD( m_regDomainsRef ), m_hWnd, 0, 0 );
check_noerr( err );
DNSServiceRefDeallocate( m_regDomainsRef );
m_regDomainsRef = NULL;
}
return err;
}
示例4: CBFDNSSDService
/* IBFDNSSDService enumerate (in long interfaceIndex, in PRBool domainType, in IBFDNSSDEnumerateListener listener); */
NS_IMETHODIMP
CBFDNSSDService::Enumerate(PRInt32 interfaceIndex, PRBool domainType, IBFDNSSDEnumerateListener *listener, IBFDNSSDService **_retval)
{
CBFDNSSDService * service = NULL;
DNSServiceErrorType dnsErr = 0;
nsresult err = 0;
*_retval = NULL;
try
{
service = new CBFDNSSDService( listener );
}
catch ( ... )
{
service = NULL;
}
if ( service == NULL )
{
err = NS_ERROR_FAILURE;
goto exit;
}
service->m_enuDomainType = domainType;
dnsErr = DNSServiceEnumerateDomains( &service->m_sdRef, domainType ? kDNSServiceFlagsBrowseDomains : kDNSServiceFlagsRegistrationDomains, interfaceIndex, ( DNSServiceDomainEnumReply ) EnumerateReply, service );
if ( dnsErr != kDNSServiceErr_NoError )
{
err = NS_ERROR_FAILURE;
goto exit;
}
if ( ( service->m_fileDesc = PR_ImportTCPSocket( DNSServiceRefSockFD( service->m_sdRef ) ) ) == NULL )
{
err = NS_ERROR_FAILURE;
goto exit;
}
if ( ( service->m_threadPool = PR_CreateThreadPool( 1, 1, 8192 ) ) == NULL )
{
err = NS_ERROR_FAILURE;
goto exit;
}
err = service->SetupNotifications();
if ( err != NS_OK)
{
goto exit;
}
listener->AddRef();
service->AddRef();
*_retval = service;
err = NS_OK;
exit:
if ( err && service )
{
delete service;
service = NULL;
}
return err;
}
示例5: register_service
void register_service(DNSServiceRef service) {
// Run until break.
int dns_sd_fd = DNSServiceRefSockFD(service);
fd_set readfds;
struct timeval tv;
int result;
while (should_run()) {
FD_ZERO(&readfds);
FD_SET(dns_sd_fd, &readfds);
tv.tv_sec = LONG_TIME;
tv.tv_usec = 0;
// highest fd in set + 1
result = select(dns_sd_fd+1, &readfds, (fd_set*)NULL, (fd_set*)NULL, &tv);
if (result > 0) {
DNSServiceErrorType err = kDNSServiceErr_NoError;
// Execute callback
if (FD_ISSET(dns_sd_fd, &readfds)) err = DNSServiceProcessResult(service);
if (err) {
// An error occured. Halt.
fprintf(stderr, "DNSServiceProcessResult returned %d\n", err);
quit();
}
} else if (errno != EINTR) {
// Error.
fprintf(stderr, "ZeroConf error (%d %s)\n", errno, strerror(errno));
if (errno != EINTR) quit();
}
}
}
示例6: qWarning
void BonjourServiceResolver::resolveBonjourRecord( const BonjourRecord& record )
{
if( isResolving() )
{
qWarning("resolve in process, aborting");
return;
}
const DNSServiceErrorType err = DNSServiceResolve( &d->dnssref, 0, 0, record.serviceName.toUtf8().constData(), record.registeredType.toUtf8().constData(),
record.replyDomain.toUtf8().constData(), Private::bonjourResolveReply, d );
if( err != kDNSServiceErr_NoError )
{
error( err );
}
else
{
const int sockfd = DNSServiceRefSockFD( d->dnssref );
if( sockfd == -1 )
{
error( kDNSServiceErr_Invalid );
}
else
{
Q_ASSERT( d->bonjourSocket == 0 );
d->bonjourSocket = new QSocketNotifier( sockfd, QSocketNotifier::Read, this );
connect( d->bonjourSocket, SIGNAL( activated( int ) ), this, SLOT( bonjourSocketReadyRead() ) );
}
}
}
示例7: assert
bool MLNetServiceHub::pollService(DNSServiceRef dnsServiceRef, double timeOutInSeconds, DNSServiceErrorType &err)
{
assert(dnsServiceRef);
err = kDNSServiceErr_NoError;
fd_set readfds;
FD_ZERO(&readfds);
int dns_sd_fd = DNSServiceRefSockFD(dnsServiceRef);
int nfds = dns_sd_fd+1;
FD_SET(dns_sd_fd, &readfds);
struct timeval tv;
tv.tv_sec = long(floor(timeOutInSeconds));
tv.tv_usec = long(1000000*(timeOutInSeconds - tv.tv_sec));
int result = select(nfds,&readfds,NULL,NULL,&tv);
if(result>0 && FD_ISSET(dns_sd_fd, &readfds))
{
err = DNSServiceProcessResult(dnsServiceRef);
return true;
}
return false;
}
示例8: register_service
void
register_service (int port)
{
int dnsfd;
GSource *source;
if (DNSServiceRegister (&g_sdref, 0, 0, NULL, "_xmms2._tcp", NULL, NULL,
g_htons (port), 0, NULL, dns_callback, NULL)
!= kDNSServiceErr_NoError) {
printf ("failed to register!\n");
exit (1);
}
dnsfd = DNSServiceRefSockFD (g_sdref);
if (dnsfd == -1) {
printf ("no fd!?\n");
exit (1);
}
pollfd = g_new0 (GPollFD, 1);
pollfd->fd = dnsfd;
pollfd->events = G_IO_IN | G_IO_HUP | G_IO_ERR;
source = g_source_new (&dns_ipc_func, sizeof (GSource));
g_source_add_poll (source, pollfd);
g_source_attach (source, NULL);
}
示例9: dlog
LONG
CSecondPage::OnServiceEvent(WPARAM inWParam, LPARAM inLParam)
{
if (WSAGETSELECTERROR(inLParam) && !(HIWORD(inLParam)))
{
dlog( kDebugLevelError, "OnServiceEvent: window error\n" );
}
else
{
SOCKET sock = (SOCKET) inWParam;
// iterate thru list
ServiceRefList::iterator begin = m_serviceRefList.begin();
ServiceRefList::iterator end = m_serviceRefList.end();
while (begin != end)
{
DNSServiceRef ref = *begin++;
check(ref != NULL);
if ((SOCKET) DNSServiceRefSockFD(ref) == sock)
{
DNSServiceProcessResult(ref);
break;
}
}
}
return ( 0 );
}
示例10: qWarning
/*!
* Attempts to resolve the service in order to determine the host and port necessary to establish a connection.
*
* If forceMulticast is set to true, QxtDiscoverableService will use a multicast request to resolve the service,
* even if the host name appears to be a unicast address (that is, outside the local network).
*
* \sa resolved
* \sa resolveError
*/
void QxtDiscoverableService::resolve(bool forceMulticast)
{
if(state() != Unknown && state() != Found) {
qWarning() << "QxtDiscoverableService: Cannot resolve service while not in Unknown or Found state";
emit resolveError(0);
return;
}
DNSServiceErrorType err;
err = DNSServiceResolve(&(qxt_d().service),
(forceMulticast ? kDNSServiceFlagsForceMulticast : 0),
qxt_d().iface,
serviceName().toUtf8().constData(),
fullServiceType().constData(),
domain().toUtf8().constData(),
QxtDiscoverableServicePrivate::resolveServiceCallback,
&qxt_d());
if(err != kDNSServiceErr_NoError) {
qxt_d().state = Unknown;
emit resolveError(err);
} else {
qxt_d().state = Resolving;
qxt_d().notifier = new QSocketNotifier(DNSServiceRefSockFD(qxt_d().service), QSocketNotifier::Read, this);
QObject::connect(qxt_d().notifier, SIGNAL(activated(int)), &qxt_d(), SLOT(socketData()));
}
}
示例11: ProcessDNSMessages
void ProcessDNSMessages() {
static boolean initialized;
if ( !initialized ) {
initialized = true;
DNSServiceErrorType err = DNSServiceBrowse (
&browseRef,
0, /* flags */
0, /* interface */
serviceName,
NULL, /* domain */
DNSServiceBrowseReplyCallback,
NULL /* context */
);
if ( err != kDNSServiceErr_NoError ) {
printf( "DNSServiceBrowse error\n" );
return;
}
}
// poll the socket for updates
int socket = DNSServiceRefSockFD( browseRef );
if ( socket <= 0 ) {
return;
}
fd_set set;
FD_ZERO( &set );
FD_SET( socket, &set );
struct timeval tv;
memset( &tv, 0, sizeof( tv ) );
if ( select( socket+1, &set, NULL, NULL, &tv ) > 0 ) {
DNSServiceProcessResult( browseRef );
}
}
示例12: g_mdns_poll_add
static gboolean
g_mdns_poll_add (GMDNS *mdns, GMDNSUserData *ud, DNSServiceRef client)
{
ud->fd = g_new0 (GPollFD, 1);
ud->fd->fd = DNSServiceRefSockFD (client);
ud->client = client;
ud->mdns = mdns;
if (ud->fd->fd == -1) {
g_free (ud->fd);
g_free (ud);
return FALSE;
}
ud->fd->events = G_IO_IN | G_IO_HUP | G_IO_ERR;
ud->source = g_source_new (&g_mdns_poll_funcs, sizeof (GSource));
g_source_set_callback (ud->source,
(GSourceFunc) g_mdns_source_dispatch,
ud, NULL);
g_source_add_poll (ud->source, ud->fd);
g_source_attach (ud->source, NULL);
return TRUE;
}
示例13: DNSServiceRegister
/*
* DnsServiceRegistrar::add
*
* Registers a new service.
*
* Parameters:
* - type: service type
* - port: port number of the registered service
* - name: service name (optional)
*
* Return value: reference of the DNS service if registration was successful, NULL otherwise
*/
DNSServiceRef DnsServiceRegistrar::add(const QString& type, quint16 port, const QString& name)
{
/* Deal with name default value */
char *nameStr;
if (name == "") {
nameStr = NULL;
} else {
nameStr = name.toUtf8().data();
}
/* Create and register the new service ref. */
DNSServiceRef ref;
DNSServiceErrorType err = DNSServiceRegister(&ref, 0, 0, nameStr, type.toUtf8().data(), NULL,
NULL, qToBigEndian(port), 0, NULL, registerCallback, this);
if (err != kDNSServiceErr_NoError) {
Model::logger().addEntry(Logger::Error, QString("Error while registering service (error code = %1)").arg(err));
return NULL;
}
/* Create the QSocketNotifier */
int sockFd = DNSServiceRefSockFD(ref);
RefNotifier *pNotif = new RefNotifier(ref, sockFd, QSocketNotifier::Read, this);
connect(pNotif, SIGNAL(activated(int)), this, SLOT(onNotifierActivated()));
return ref;
}
示例14: DNSServiceRefSockFD
void AutoDiscoveryServerImpl::update()
{
int dns_sd_fd = client ? DNSServiceRefSockFD(client ) : -1;
int nfds = dns_sd_fd + 1;
fd_set readfds;
struct timeval tv;
int result;
// (dns_sd_fd2 > dns_sd_fd) nfds = dns_sd_fd2 + 1;
// 1. Set up the fd_set as usual here.
// This example client has no file descriptors of its own,
// but a real application would call FD_SET to add them to the set here
FD_ZERO(&readfds);
// 2. Add the fd for our client(s) to the fd_set
if (client ) FD_SET(dns_sd_fd , &readfds);
//if (client_pa) FD_SET(dns_sd_fd2, &readfds);
// 3. Set up the timeout.
tv.tv_sec = 0;
tv.tv_usec = 0;
result = select(nfds, &readfds, (fd_set*)NULL, (fd_set*)NULL, &tv);
if (result > 0)
{
DNSServiceErrorType err = kDNSServiceErr_NoError;
if (client && FD_ISSET(dns_sd_fd , &readfds)) err = DNSServiceProcessResult(client );
// else if (client_pa && FD_ISSET(dns_sd_fd2, &readfds)) err = DNSServiceProcessResult(client_pa);
// if (err) { fprintf(stderr, "DNSServiceProcessResult returned %d\n", err); stopNow = 1; }
}
}
示例15: lock
void CZeroconfMDNS::doStop()
{
{
CSingleLock lock(m_data_guard);
CLog::Log(LOGDEBUG, "ZeroconfMDNS: Shutdown services");
for(tServiceMap::iterator it = m_services.begin(); it != m_services.end(); ++it)
{
DNSServiceRefDeallocate(it->second.serviceRef);
TXTRecordDeallocate(&it->second.txtRecordRef);
CLog::Log(LOGDEBUG, "ZeroconfMDNS: Removed service %s", it->first.c_str());
}
m_services.clear();
}
{
CSingleLock lock(m_data_guard);
#if defined(TARGET_WINDOWS_STORE)
CLog::Log(LOGERROR, "ZeroconfMDNS: WSAAsyncSelect not yet supported for TARGET_WINDOWS_STORE");
#else
WSAAsyncSelect( (SOCKET) DNSServiceRefSockFD( m_service ), g_hWnd, BONJOUR_EVENT, 0 );
#endif //TARGET_WINDOWS
if (m_service)
DNSServiceRefDeallocate(m_service);
m_service = NULL;
}
}