mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-21 20:56:39 +00:00
Merge "stun.c: Fix ast_stun_request() erratic timeout."
This commit is contained in:
11
main/stun.c
11
main/stun.c
@@ -411,6 +411,7 @@ int ast_stun_request(int s, struct sockaddr_in *dst,
|
|||||||
/* send request, possibly wait for reply */
|
/* send request, possibly wait for reply */
|
||||||
struct sockaddr_in src;
|
struct sockaddr_in src;
|
||||||
socklen_t srclen;
|
socklen_t srclen;
|
||||||
|
struct timeval start;
|
||||||
|
|
||||||
/* Send STUN message. */
|
/* Send STUN message. */
|
||||||
res = stun_send(s, dst, req);
|
res = stun_send(s, dst, req);
|
||||||
@@ -424,12 +425,20 @@ int ast_stun_request(int s, struct sockaddr_in *dst,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
start = ast_tvnow();
|
||||||
try_again:
|
try_again:
|
||||||
/* Wait for response. */
|
/* Wait for response. */
|
||||||
{
|
{
|
||||||
struct pollfd pfds = { .fd = s, .events = POLLIN };
|
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) {
|
if (res < 0) {
|
||||||
/* Error */
|
/* Error */
|
||||||
continue;
|
continue;
|
||||||
|
Reference in New Issue
Block a user