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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Nov 24 11:07:46 MST 2006


Author: rizzo
Date: Fri Nov 24 12:07:46 2006
New Revision: 47996

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47996
Log:
Merge the two similar parts that document struct sip_request.

Add some profiling code to determine the cost of basic operations
such as

	ast_mutex_init(&m);
	ast_mutex_destroy(&m);
	buf = malloc(res+1);
	buf2 = ast_calloc(1,res+1);
	bcopy(req.data, buf, res+1);


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=47996&r1=47995&r2=47996
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Fri Nov 24 12:07:46 2006
@@ -597,7 +597,8 @@
 /*!
  * Incoming packet, or outgoing one.
  * For incoming packets, we first store the data from the socket in data[],
- * then call parse_request() and req.method = find_sip_method();
+ * adding a trailing \0 to make string parsing routines happy.
+ * Then call parse_request() and req.method = find_sip_method();
  * to initialize the other fields. The \r\n at the end of line is
  * replaced by \0, so that data[] is not a conforming one anymore.
  * flags has SIP_PKT_PARSED set to remember that we can run get_header()
@@ -608,6 +609,17 @@
  * and then fill the rest with add_header() and add_line().
  * The \r\n at the end of the line are still there, so the get_header()
  * and so on functions don't work on these packets.
+ *
+ * Note that in all cases, len is the total number of bytes used in data[]
+ * excluding the trailing \0. It is rarely used.
+ * According to the SIP spec, header and body should be separated by an
+ * empty line, which we store as the last of the headers.
+ *
+ * parse_request() splits the first line as follows:
+ * Requests have in the first line	METHOD URI SIP/2.0
+ *	rlPart1 = method; rlPart2 = uri;
+ * Responses have in the first line	SIP/2.0 code description
+ *	rlPart1 = SIP/2.0; rlPart2 = code + description;
  */
 
 struct sip_request {
@@ -630,25 +642,6 @@
 {
 	return ast_test_flag(req, SIP_PKT_IGNORE);
 }
-
-/*
- * A sip packet is stored into the data[] buffer, with the header followed
- * by an empty line and the body of the message.
- * On outgoing packets, data is accumulated in data[] with len reflecting
- * the next available byte, headers and lines count the number of lines
- * in both parts. There are no '\0' in data[0..len-1].
- *
- * On received packet, the input read from the socket is copied into data[],
- * len is set and the string is NUL-terminated. Then a parser fills up
- * the other fields -header[] and line[] to point to the lines of the
- * message, rlPart1 and rlPart2 parse the first lnie as below:
- *
- * Requests have in the first line	METHOD URI SIP/2.0
- *	rlPart1 = method; rlPart2 = uri;
- * Responses have in the first line	SIP/2.0 code description
- *	rlPart1 = SIP/2.0; rlPart2 = code + description;
- *
- */
 
 /*! \brief structure used in transfers */
 struct sip_dual {
@@ -15284,12 +15277,18 @@
 	int lockretry;
 	int buflen = sizeof(req.data) - 1; /* leave an extra byte at the end for '\0' */
 	static int prof_memset = -1, prof_recv = -1, prof_parse = -1, prof_find = -1;
+	static int prof_malloc = -1, prof_calloc, prof_copy = -1, prof_mtx_init, prof_mtx_destroy;
 
 	if (prof_memset == -1) {	/* allocate profiling counters */
 		prof_memset = ast_add_profile("sip_read-memset", 0);
 		prof_recv = ast_add_profile("sip_read-recvfrom", 0);
 		prof_parse = ast_add_profile("sip_read-parse", 0);
 		prof_find = ast_add_profile("sip_read-find_call", 0);
+		prof_calloc = ast_add_profile("sip_read-ast_calloc sip_request", 0);
+		prof_malloc = ast_add_profile("sip_read-malloc sip_request", 0);
+		prof_copy = ast_add_profile("sip_read-copy body", 0);
+		prof_mtx_init = ast_add_profile("sip_read-mtx_init", 0);
+		prof_mtx_destroy = ast_add_profile("sip_read-mtx_destroy", 0);
 	}
 	ast_mark(prof_memset, 1);
 	memset(&req, 0, sizeof(req));
@@ -15314,6 +15313,36 @@
 		return 1;
 	}
 	req.data[res] = '\0';
+{	/* debugging */
+	char *buf, *buf2;
+	ast_mutex_t m;
+
+	ast_mark(prof_mtx_init, 1);
+	ast_mutex_init(&m);
+	ast_mark(prof_mtx_init, 0);
+
+	ast_mark(prof_mtx_destroy, 1);
+	ast_mutex_destroy(&m);
+	ast_mark(prof_mtx_destroy, 0);
+
+	ast_mark(prof_malloc, 1);
+	buf = malloc(res+1);
+	ast_mark(prof_malloc, 0);
+	
+	ast_mark(prof_calloc, 1);
+	buf2 = ast_calloc(1,res+1);
+	ast_mark(prof_calloc, 0);
+	if (buf2)
+		free(buf2);
+
+	if (buf) {
+		ast_mark(prof_copy, 1);
+		bcopy(req.data, buf, res+1);
+		ast_mark(prof_copy, 0);
+		free(buf);
+	}
+}
+		
 	if (option_debug && res == buflen)
 		ast_log(LOG_DEBUG, "Received packet exceeds buffer. Data is possibly lost\n");
 	req.len = res;



More information about the asterisk-commits mailing list