diff options
author | Joshua Colp <jcolp@digium.com> | 2017-04-12 04:54:33 -0500 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2017-04-12 04:54:33 -0500 |
commit | c5536eaee977caca360ae36b499bb5070f13d6a0 (patch) | |
tree | b1cc172892bfdee8ce33ac75e10d05599a7b1cd6 | |
parent | 3c32680a8a32e2595913280525c67dcd56902796 (diff) | |
parent | 7c37365f03aed7b7bf9f89a96272fd37d9f904d9 (diff) |
Merge "stun.c: Fix ast_stun_request() erratic timeout."
-rw-r--r-- | main/stun.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/main/stun.c b/main/stun.c index 356266c94..77ced82ae 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; |