getaddrinfo hanging but not sure how to properly poll using getaddrinfo_a

Viewed 112

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?

0 Answers
Related