[asterisk-commits] russell: branch russell/iax2_ff r70807 - /team/russell/iax2_ff/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 21 14:47:54 CDT 2007


Author: russell
Date: Thu Jun 21 14:47:53 2007
New Revision: 70807

URL: http://svn.digium.com/view/asterisk?view=rev&rev=70807
Log:
Reduce the number of memcpy's in half

Modified:
    team/russell/iax2_ff/channels/chan_iax2.c

Modified: team/russell/iax2_ff/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/russell/iax2_ff/channels/chan_iax2.c?view=diff&rev=70807&r1=70806&r2=70807
==============================================================================
--- team/russell/iax2_ff/channels/chan_iax2.c (original)
+++ team/russell/iax2_ff/channels/chan_iax2.c Thu Jun 21 14:47:53 2007
@@ -685,7 +685,7 @@
 struct iax2_pkt_buf {
 	AST_LIST_ENTRY(iax2_pkt_buf) entry;
 	size_t len;
-	unsigned char buf[0];
+	unsigned char buf[1];
 };
 
 struct iax2_thread {
@@ -703,8 +703,10 @@
 	pthread_t threadid;
 	int threadnum;
 	struct sockaddr_in iosin;
-	unsigned char buf[4096]; 
-	int iores;
+	unsigned char readbuf[4096]; 
+	unsigned char *buf;
+	size_t buf_len;
+	size_t buf_size;
 	int iofd;
 	time_t checktime;
 	ast_mutex_t lock;
@@ -6282,6 +6284,8 @@
 	iaxs[fr->callno]->remote_rr.ooo = ies->rr_ooo;
 }
 
+static int socket_process(struct iax2_thread *thread);
+
 /*!
  * \brief Check to see if they are deferred full frames for this thread
  *
@@ -6293,14 +6297,17 @@
 {
 	struct iax2_pkt_buf *pkt_buf;
 
-	if (AST_LIST_EMPTY(&thread->full_frames))
-		return 0;
-	
-	pkt_buf = AST_LIST_REMOVE_HEAD(&thread->full_frames, entry);
-	memcpy(thread->buf, pkt_buf->buf, pkt_buf->len);
-	thread->iores = pkt_buf->len;
-
-	ast_free(pkt_buf);
+	while ((pkt_buf = AST_LIST_REMOVE_HEAD(&thread->full_frames, entry))) {
+		thread->buf = pkt_buf->buf;
+		thread->buf_len = pkt_buf->len;
+		thread->buf_size = pkt_buf->len + 1;
+		
+		socket_process(thread);
+
+		thread->buf = NULL;
+
+		ast_free(pkt_buf);
+	}
 
 	return 1;
 }
@@ -6316,10 +6323,10 @@
 	struct iax2_pkt_buf *pkt_buf, *cur_pkt_buf;
 	struct ast_iax2_full_hdr *fh, *cur_fh;
 
-	if (!(pkt_buf = ast_calloc(1, sizeof(*pkt_buf) + thread->iores)))
+	if (!(pkt_buf = ast_calloc(1, sizeof(*pkt_buf) + thread->buf_len)))
 		return;
 
-	pkt_buf->len = thread->iores;
+	pkt_buf->len = thread->buf_len;
 	memcpy(pkt_buf->buf, thread->buf, pkt_buf->len);
 
 	fh = (struct ast_iax2_full_hdr *) pkt_buf->buf;
@@ -6355,8 +6362,10 @@
 
 	len = sizeof(thread->iosin);
 	thread->iofd = fd;
-	thread->iores = recvfrom(fd, thread->buf, sizeof(thread->buf), 0, (struct sockaddr *) &thread->iosin, &len);
-	if (thread->iores < 0) {
+	thread->buf_len = recvfrom(fd, thread->readbuf, sizeof(thread->buf), 0, (struct sockaddr *) &thread->iosin, &len);
+	thread->buf_size = sizeof(thread->readbuf);
+	thread->buf = thread->readbuf;
+	if (thread->buf_len < 0) {
 		if (errno != ECONNREFUSED && errno != EAGAIN)
 			ast_log(LOG_WARNING, "Error: %s\n", strerror(errno));
 		handle_error();
@@ -6448,7 +6457,7 @@
 	fr->callno = 0;
 
 	/* Copy frequently used parameters to the stack */
-	res = thread->iores;
+	res = thread->buf_len;
 	fd = thread->iofd;
 	memcpy(&sin, &thread->iosin, sizeof(sin));
 
@@ -6730,7 +6739,7 @@
 		}
 		/* Ensure text frames are NULL-terminated */
 		if (f.frametype == AST_FRAME_TEXT && thread->buf[res - 1] != '\0') {
-			if (res < sizeof(thread->buf))
+			if (res < thread->buf_size)
 				thread->buf[res++] = '\0';
 			else /* Trims one character from the text message, but that's better than overwriting the end of the buffer. */
 				thread->buf[res - 1] = '\0';
@@ -7865,9 +7874,8 @@
 		case IAX_IOSTATE_READY:
 			thread->actions++;
 			thread->iostate = IAX_IOSTATE_PROCESSING;
-			do {
-				socket_process(thread);
-			} while (check_deferred_full_frames(thread));
+			socket_process(thread);
+			check_deferred_full_frames(thread);
 			break;
 		case IAX_IOSTATE_SCHEDREADY:
 			thread->actions++;




More information about the asterisk-commits mailing list