Abort a call to getaddrinfo()

807 Views Asked by At

getaddrinfo() is a blocking function.

How can I abort a getaddrinfo() call?

For example when closing my application I want to abort existing calls to this function.

2

There are 2 best solutions below

1
On

You can't abort a function call like that.

If the function call provides a means for you to abort or set a timeout then you could, but this one does not, and neither do most function calls.

But, you can perform these lookups in a separate thread, and now you can issue an abort to the thread doing those lookups.

Note, doing the lookup in a thread and aborting it does not guarantee that the call will immediately end nor does it mean the thread will end immediately.

This is especially the case if the call is misbehaving or not functioning correctly.

1
On

getaddrinfo() is a blocking function that you cannot abort.

On Windows 8 and later, you can use GetAddrInfoEx() instead. The Unicode version (GetAddrInfoExW()) supports a caller-provided timeout as well as Overlapped I/O, or it can return a HANDLE for an asynchronous task that can then be passed to GetAddrInfoExCancel().