[asterisk-commits] rizzo: branch rizzo/astobj2 r47937 - /team/rizzo/astobj2/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Nov 22 11:13:21 MST 2006


Author: rizzo
Date: Wed Nov 22 12:13:20 2006
New Revision: 47937

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47937
Log:
small simplification to comments and code in sipsock_read.

trunk candidate


Modified:
    team/rizzo/astobj2/channels/chan_sip.c

Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?view=diff&rev=47937&r1=47936&r2=47937
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Wed Nov 22 12:13:20 2006
@@ -15176,13 +15176,16 @@
 	int nounlock;
 	int recount = 0;
 	int lockretry;
+	int buflen = sizeof(req.data) - 1; /* leave an extra byte at the end for '\0' */
 
 	memset(&req, 0, sizeof(req));
 	/*
-	 * There is a short window during a reload when this might fail.
-	 * Just live with it.
+	 * There is a short window during a reload when recvfrom
+	 * might fail because __sipsock is being closed and reopened.
+	 * Just live with it, it is not fatal, the network could have
+	 * dropped the packet anyways.
 	 */
-	res = recvfrom(__sipsock, req.data, sizeof(req.data) - 1, 0, (struct sockaddr *)&sin, &len);
+	res = recvfrom(__sipsock, req.data, buflen, 0, (struct sockaddr *)&sin, &len);
 	if (res < 0) {
 #if !defined(__FreeBSD__)
 		if (errno == EAGAIN)
@@ -15193,11 +15196,9 @@
 			ast_log(LOG_WARNING, "Recv error: %s\n", strerror(errno));
 		return 1;
 	}
-	if (option_debug && res == sizeof(req.data)) {
+	req.data[res] = '\0';
+	if (option_debug && res == buflen)
 		ast_log(LOG_DEBUG, "Received packet exceeds buffer. Data is possibly lost\n");
-		req.data[sizeof(req.data) - 1] = '\0';
-	} else
-		req.data[res] = '\0';
 	req.len = res;
 	if(sip_debug_test_addr(&sin))	/* Set the debug flag early on packet level */
 		ast_set_flag(&req, SIP_PKT_DEBUG);



More information about the asterisk-commits mailing list