From f11c40d889584d18e64edabe68a8d96069a0a7da Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 23 Jul 2014 11:26:23 -0500 Subject: [PATCH] FS-6680 #resolve --- src/switch_nat.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/switch_nat.c b/src/switch_nat.c index 503fa891c3..445d2f2b6d 100644 --- a/src/switch_nat.c +++ b/src/switch_nat.c @@ -151,11 +151,7 @@ static int get_pmp_pubaddr(char *pub_addr) char *pubaddr = NULL; natpmp_t natpmp; const char *err = NULL; - switch_pollfd_t *pollfd = NULL; - switch_socket_t *sock = NULL; - switch_memory_pool_t *pool; - int32_t num = 0; - switch_status_t status = SWITCH_STATUS_SUCCESS; + int pflags; if ((r = initnatpmp(&natpmp)) < 0) { err = "init failed"; @@ -167,15 +163,6 @@ static int get_pmp_pubaddr(char *pub_addr) goto end; } - switch_core_new_memory_pool(&pool); - - switch_os_sock_put(&sock, &natpmp.s, pool); - - if (switch_socket_create_pollset(&pollfd, sock, SWITCH_POLLIN | SWITCH_POLLERR, pool) != SWITCH_STATUS_SUCCESS) { - err = "cannot create pollset"; - goto end; - } - do { struct timeval timeout = { 1, 0 }; i++; @@ -185,16 +172,14 @@ static int get_pmp_pubaddr(char *pub_addr) err = "get timeout failed"; goto end; } - - status = switch_poll(pollfd, 1, &num, switch_interval_time_from_timeval(&timeout)); - if (!(status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_TIMEOUT)) { - err = "poll failed"; + pflags = switch_wait_sock(natpmp.s, 100, SWITCH_POLL_READ | SWITCH_POLL_ERROR | SWITCH_POLL_HUP); + + if ((pflags & SWITCH_POLL_ERROR) || (pflags & SWITCH_POLL_HUP)) { + err = "wait sock failed"; goto end; } - r = readnatpmpresponseorretry(&natpmp, &response); - } while (r == NATPMP_TRYAGAIN && i < max); if (r < 0) { @@ -210,8 +195,6 @@ static int get_pmp_pubaddr(char *pub_addr) end: - switch_core_destroy_memory_pool(&pool); - if (err) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error checking for PMP [%s]\n", err); }