[asterisk-commits] russell: branch russell/ast_cli_tls r38138 -
/team/russell/ast_cli_tls/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Sun Jul 23 12:37:43 MST 2006
Author: russell
Date: Sun Jul 23 14:37:42 2006
New Revision: 38138
URL: http://svn.digium.com/view/asterisk?rev=38138&view=rev
Log:
merge further changes to thread local storage support for ast_cli().
This removes the length limitation on the resulting string by allowing the size
of the buffer to grow as needed.
Modified:
team/russell/ast_cli_tls/ (props changed)
team/russell/ast_cli_tls/cli.c
Propchange: team/russell/ast_cli_tls/
------------------------------------------------------------------------------
automerge = *
Propchange: team/russell/ast_cli_tls/
------------------------------------------------------------------------------
automerge-email = russell at digium.com
Propchange: team/russell/ast_cli_tls/
------------------------------------------------------------------------------
svnmerge-integrated = /trunk:1-38136
Modified: team/russell/ast_cli_tls/cli.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_cli_tls/cli.c?rev=38138&r1=38137&r2=38138&view=diff
==============================================================================
--- team/russell/ast_cli_tls/cli.c (original)
+++ team/russell/ast_cli_tls/cli.c Sun Jul 23 14:37:42 2006
@@ -54,8 +54,8 @@
static pthread_key_t ast_cli_buf_key;
static pthread_once_t ast_cli_buf_once = PTHREAD_ONCE_INIT;
-/*! \brief Maximum length of resulting strings in ast_cli() */
-#define AST_CLI_MAXSTRLEN 16384
+/*! \brief Initial buffer size for resulting strings in ast_cli() */
+#define AST_CLI_MAXSTRLEN 256
static void ast_cli_buf_key_create(void)
{
@@ -64,23 +64,37 @@
void ast_cli(int fd, char *fmt, ...)
{
- char *buf;
+ void *buf;
+ unsigned int *len;
+ char *str;
int res;
va_list ap;
pthread_once(&ast_cli_buf_once, ast_cli_buf_key_create);
- if (!(buf = pthread_getspecific(ast_cli_buf_key))) {
- if (!(buf = ast_malloc(AST_CLI_MAXSTRLEN)))
+ if (!(len = buf = pthread_getspecific(ast_cli_buf_key))) {
+ if (!(len = buf = ast_malloc(AST_CLI_MAXSTRLEN + sizeof(*len))))
return;
+ *len = AST_CLI_MAXSTRLEN;
pthread_setspecific(ast_cli_buf_key, buf);
}
+ str = buf + sizeof(*len);
va_start(ap, fmt);
- res = vsnprintf(buf, AST_CLI_MAXSTRLEN, fmt, ap);
+ res = vsnprintf(str, *len, fmt, ap);
+ while (res >= *len) {
+ *len *= 2;
+ if (!(len = buf = ast_realloc(buf, *len + sizeof(*len)))) {
+ va_end(ap);
+ return;
+ }
+ pthread_setspecific(ast_cli_buf_key, buf);
+ str = buf + sizeof(*len);
+ res = vsnprintf(str, *len, fmt, ap);
+ }
va_end(ap);
if (res > 0)
- ast_carefulwrite(fd, buf, strlen(buf), 100);
+ ast_carefulwrite(fd, str, strlen(str), 100);
}
static AST_LIST_HEAD_STATIC(helpers, ast_cli_entry);
More information about the asterisk-commits
mailing list