diff options
author | Richard Mudgett <rmudgett@digium.com> | 2017-04-06 17:31:14 -0500 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2017-04-11 12:58:35 -0500 |
commit | 7c37365f03aed7b7bf9f89a96272fd37d9f904d9 (patch) | |
tree | 21b33ad2ad990a7620e4aa1bb3534bd34227286e /main/stun.c | |
parent | 8d323c74fa60fd1eb411336753ef4052faf7b309 (diff) |
stun.c: Fix ast_stun_request() erratic timeout.
If ast_stun_request() receives packets other than a STUN response then we
could conceivably never exit if we continue to receive packets with less
than three seconds between them.
* Fix poll timeout to keep track of the time when we sent the STUN
request. We will now send a STUN request every three seconds regardless
of how many other packets we receive while waiting for a response until we
have completed three STUN request transmission cycles.
Change-Id: Ib606cb08585e06eb50877f67b8d3bd385a85c266
Diffstat (limited to 'main/stun.c')
-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; |