Cancelling a call to getnameinfo()

I am making concurrent calls to getnameinfo() by submitting each call to a separate dispatch_queue.


If there is some problem or slowness in a dns lookup I would like to cancel that call before the default timeout (30 secs?) has passed.


Is it possible to raise SIGALRM to target a specific dispatch_queue in order to interrupt whatever system call getnameinfo() is hanging on. The dispatch_sources approach seems to invoke the signal handler from a specified queue but I'm not sure which of my dispatch queues will actually receive the interrupt.


Or is there some other sneaky way to cause getnameinfo() to return early.


Sorry if this is not the correct forum, but I am currently working with Swift and managing my dispatch_queues from Swift.


Regards

Bryan

Accepted Reply

There’s no way you can reasonably cancel

getnameinfo
. Trust me, signals are not the answer (signals are never the answer :-)

The underlying DNS implementation on Apple platforms is fully async and does support cancellation. The problem here is that BSD APIs don’t expose that support.

Are you doing anything special with

getnameinfo
? In typical uses cases you can get equivalent behaviour by moving ‘up’ to CFHost, a type that does support async operations. CFHost isn’t a lot of fun to call from Swift; post back if you get stuck.

If you need more control you can drop ‘down’ to

<dns_sd.h>
, but that’s less fun because you have to monkey with DNS records directly (there is an equivalent to
getaddrinfo
, namely
DNSServiceGetAddrInfo
, but not for
getnameinfo
).

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

There’s no way you can reasonably cancel

getnameinfo
. Trust me, signals are not the answer (signals are never the answer :-)

The underlying DNS implementation on Apple platforms is fully async and does support cancellation. The problem here is that BSD APIs don’t expose that support.

Are you doing anything special with

getnameinfo
? In typical uses cases you can get equivalent behaviour by moving ‘up’ to CFHost, a type that does support async operations. CFHost isn’t a lot of fun to call from Swift; post back if you get stuck.

If you need more control you can drop ‘down’ to

<dns_sd.h>
, but that’s less fun because you have to monkey with DNS records directly (there is an equivalent to
getaddrinfo
, namely
DNSServiceGetAddrInfo
, but not for
getnameinfo
).

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Many thanks Quinn. Its all working now after a bit of research on CFHost. I did the heavy lifting in a C++ class and exported simple C interfaces to use in the Swift code.

Regards

Bryan