[Freeswitch-trunk] [commit] r13557 - freeswitch/trunk/src

FreeSWITCH SVN anthm at freeswitch.org
Tue Jun 2 15:46:38 PDT 2009


Author: anthm
Date: Tue Jun  2 17:46:38 2009
New Revision: 13557

Log:
fix long delay in nat detection

Modified:
   freeswitch/trunk/src/switch_nat.c

Modified: freeswitch/trunk/src/switch_nat.c
==============================================================================
--- freeswitch/trunk/src/switch_nat.c	(original)
+++ freeswitch/trunk/src/switch_nat.c	Tue Jun  2 17:46:38 2009
@@ -101,11 +101,11 @@
 
 static int init_pmp(void)
 {
-	int r = 0;
+	int r = 0, i = 0, max = 5;
 	natpmpresp_t response;
 	char *pubaddr = NULL;
 	fd_set fds;
-	struct timeval timeout;
+
 
 	initnatpmp(&nat_globals.natpmp);
 	r = sendpublicaddressrequest(&nat_globals.natpmp);
@@ -115,12 +115,16 @@
 	}
 
 	do {
+		struct timeval timeout = { 1, 0};
+		i++;
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for PMP %d/%d\n", i, max);
+
 		FD_ZERO(&fds);
 		FD_SET(nat_globals.natpmp.s, &fds);
 		getnatpmprequesttimeout(&nat_globals.natpmp, &timeout);
 		select(FD_SETSIZE, &fds, NULL, NULL, &timeout);
 		r = readnatpmpresponseorretry(&nat_globals.natpmp, &response);
-	} while(r == NATPMP_TRYAGAIN);
+	} while(r == NATPMP_TRYAGAIN && i < max);
 
 	if (r < 0) {
 		goto end;
@@ -147,13 +151,12 @@
 	switch_find_local_ip(nat_globals.pvt_addr, sizeof(nat_globals.pvt_addr), NULL, AF_INET);
 
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Detecting NAT\n");
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Scanning for NAT\n");
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for PMP\n");
 	init_pmp();
 
-	if (nat_globals.nat_type) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for UPNP\n");
+	if (!nat_globals.nat_type) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for UPnP\n");
 		init_upnp();
 	}
 	
@@ -163,7 +166,7 @@
 		switch_core_set_variable("nat_type", nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp");
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "NAT detected type: %s\n", nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp");
 	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "No PMP or uPNP NAT device detected!\n");
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "No PMP or UPnP NAT detected!\n");
 	}
 }
 



More information about the Freeswitch-trunk mailing list