From e0214af42279f03dafbf92236b06418a29f675fa Mon Sep 17 00:00:00 2001 From: Sergey Lyubka <valenok@gmail.com> Date: Sun, 2 Mar 2014 10:07:30 +0000 Subject: [PATCH] Using private ns_avprintf() in mg_printf_data() --- mongoose.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/mongoose.c b/mongoose.c index cde68d3e0..81f4837c6 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2282,33 +2282,22 @@ void mg_send_data(struct mg_connection *c, const void *data, int data_len) { void mg_printf_data(struct mg_connection *c, const char *fmt, ...) { struct connection *conn = MG_CONN_2_CONN(c); - struct iobuf *io = &conn->ns_conn->send_iobuf; va_list ap; - int len, n, iolen; - char *p; + int len; + char mem[IOBUF_SIZE], *buf = mem; terminate_headers(c); - // Remember original io->len - iolen = io->len; - // Write the placeholder for the chunk size - p = io->buf + io->len; - iobuf_append(io, " \r\n", 10); - - // Write chunk itself va_start(ap, fmt); - len = ns_vprintf(conn->ns_conn, fmt, ap); + len = ns_avprintf(&buf, sizeof(mem), fmt, ap); va_end(ap); - // Recalculate pointer p because of potential realloc within iobuf_append - p = io->buf + iolen; - - // Record size - n = mg_snprintf(p, 7, "%X", len); - p[n] = ' '; - - // Write terminating new line - mg_write(c, "\r\n", 2); + if (len > 0) { + write_chunk((struct connection *) conn, buf, len); + } + if (buf != mem && buf != NULL) { + free(buf); + } } #if !defined(MONGOOSE_NO_WEBSOCKET) || !defined(MONGOOSE_NO_AUTH) -- GitLab