[asterisk-commits] russell: trunk r77791 - /trunk/res/res_agi.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 30 14:35:34 CDT 2007


Author: russell
Date: Mon Jul 30 14:35:33 2007
New Revision: 77791

URL: http://svn.digium.com/view/asterisk?view=rev&rev=77791
Log:
Improve ast_agi_fdprintf() by using the ast_str() API.
 * Use a thread local ast_str for building the string that will be written out
   to the console for debug, and to the FD for the AGI itself, instead of allocating
   a buffer on the heap every time the function is called.
 * Use the information contained within the ast_str to determine how many bytes
   need to be written instead of calling strlen().

Modified:
    trunk/res/res_agi.c

Modified: trunk/res/res_agi.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_agi.c?view=diff&rev=77791&r1=77790&r2=77791
==============================================================================
--- trunk/res/res_agi.c (original)
+++ trunk/res/res_agi.c Mon Jul 30 14:35:33 2007
@@ -115,14 +115,20 @@
 
 static agi_command *find_command(char *cmds[], int exact);
 
+AST_THREADSTORAGE(agi_buf);
+#define AGI_BUF_INITSIZE 256
+
 int ast_agi_fdprintf(int fd, char *fmt, ...)
 {
-	char *stuff;
 	int res = 0;
-
 	va_list ap;
+	struct ast_str *buf;
+
+	if (!(buf = ast_str_thread_get(&agi_buf, AGI_BUF_INITSIZE)))
+		return -1;
+
 	va_start(ap, fmt);
-	res = vasprintf(&stuff, fmt, ap);
+	res = ast_str_set_va(&buf, 0, fmt, ap);
 	va_end(ap);
 
 	if (res == -1) {
@@ -131,9 +137,9 @@
 	}
 
 	if (agidebug)
-		ast_verbose("AGI Tx >> %s", stuff);
-	ast_carefulwrite(fd, stuff, strlen(stuff), 100);
-	ast_free(stuff);
+		ast_verbose("AGI Tx >> %s", buf->str);
+
+	ast_carefulwrite(fd, buf->str, buf->used, 100);
 
 	return res;
 }




More information about the asterisk-commits mailing list