I think getaddrinfo_a is cancellable, including the ability to block with a timeout. It is a glibc extension.