diff --git a/main/stun.c b/main/stun.c index 356266c94d6604b1db41fdcc44b3569a39622423..77ced82ae0ac5331d412b7d28ec4eafe999c646f 100644 --- a/main/stun.c +++ b/main/stun.c @@ -411,6 +411,7 @@ int ast_stun_request(int s, struct sockaddr_in *dst, /* send request, possibly wait for reply */ struct sockaddr_in src; socklen_t srclen; + struct timeval start; /* Send STUN message. */ res = stun_send(s, dst, req); @@ -424,12 +425,20 @@ int ast_stun_request(int s, struct sockaddr_in *dst, break; } + start = ast_tvnow(); try_again: /* Wait for response. */ { struct pollfd pfds = { .fd = s, .events = POLLIN }; + int ms; - res = ast_poll(&pfds, 1, 3000); + ms = ast_remaining_ms(start, 3000); + if (ms <= 0) { + /* No response, timeout */ + res = 1; + continue; + } + res = ast_poll(&pfds, 1, ms); if (res < 0) { /* Error */ continue;