Use the good old select() . This is what I have at the moment:
- (void)updateDnsRecords { if (self.dnsUpdatePending == YES) { return; } else { self.dnsUpdatePending = YES; } NSLog(@"DNS update"); DNSServiceRef sdRef; DNSServiceErrorType err; const char* host = [self.dnsHost UTF8String]; if (host != NULL) { NSTimeInterval remainingTime = self.dnsUpdateTimeout; NSDate* startTime = [NSDate date]; err = DNSServiceQueryRecord(&sdRef, 0, 0, host, kDNSServiceType_SRV, kDNSServiceClass_IN, processDnsReply, &remainingTime);
Here's an Apple SRVResolver sample from which I got RR parsing.
In this example, Apple mentions that it can block forever, but, oddly enough, we recommend using NSTimer when trying to add a timeout on your own. But I think using select() much better.
I have one task: Deploy the clearing cache using DNSServiceReconfirmRecord . But now this will not happen.
Know this code works, but I'm still testing it.
You need to add libresolv.dylib to the Xcode project “Related Structures and Libraries”.
source share