From: Anthony Minessale Date: Tue, 4 Dec 2007 21:55:48 +0000 (+0000) Subject: fix possible block in rtp setup X-Git-Tag: v1.0-rc1~1320 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5046d63c17df72d5ce44899eb32c992ca8a01da;p=thirdparty%2Ffreeswitch.git fix possible block in rtp setup git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6503 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 51dee6023a..364366e96b 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -329,7 +329,9 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_local_address(switch_rtp_t *rtp_s switch_socket_t *new_sock = NULL, *old_sock = NULL; switch_status_t status = SWITCH_STATUS_FALSE; char o[5] = "TEST", i[5] = ""; - switch_size_t len; + switch_size_t len, ilen = 0; + int x; + *err = NULL; if (switch_sockaddr_info_get(&rtp_session->local_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS) { @@ -357,10 +359,28 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_local_address(switch_rtp_t *rtp_s } len = sizeof(i); + switch_socket_opt_set(new_sock, SWITCH_SO_NONBLOCK, TRUE); + switch_socket_sendto(new_sock, rtp_session->local_addr, 0, (void *) o, &len); - switch_socket_recvfrom(rtp_session->from_addr, new_sock, 0, (void *) i, &len); - if (!len) { + x = 0; + while(!ilen) { + ilen = len; + switch_status_t status = switch_socket_recvfrom(rtp_session->from_addr, new_sock, 0, (void *) i, &ilen); + + if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { + break; + } + + if (++x > 500) { + break; + } + switch_yield(1000); + } + switch_socket_opt_set(new_sock, SWITCH_SO_NONBLOCK, FALSE); + + if (!ilen) { + *err = "Send myself a packet failed!"; goto done; }