2

I have a fairly large application that makes a call to getaddrinfo. Every now and again it seems like getaddrinfo hangs. I suspect that we are dropping the request somewhere and getaddrinfo never gets a response. I'd like to have a retry counter with a timeout.

Im not sure how to implement a timeout though for this. I think I would obviously need to use getaddrinfo_a but just don't know how to. I saw in another post (gai_cancel() takes a really long time to succeed) that gai_cancel will timeout after 20 seconds but not sure where to verify that. If that's the case then I can do the following sudo code, correct?

while (count < TIMEOUT_COUNT)
{
    getaddrinfo_a(...);
    ret = gai_cancel(...);
    if (EAI_ALLDONE == ret)
    {
        // SUCCESS!!!
        break;
    }
    // FAILED or timed out
    count++;
}

Or is there another way to achieve the same effect as above?

TreeWater
  • 761
  • 6
  • 13
  • What mode are you calling `getaddrinfo_a()`? `GAI_NOWAIT` is probably the most interesting use case, and then it would not make sense to call `gai_cancel()` right after. – Allan Wind Jul 20 '22 at 05:32

0 Answers0