mirror of
https://github.com/cesanta/mongoose.git
synced 2025-08-06 13:37:34 +08:00
Using private ns_avprintf() in mg_printf_data()
This commit is contained in:
parent
df5e997ea7
commit
e0214af422
29
mongoose.c
29
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, ...) {
|
void mg_printf_data(struct mg_connection *c, const char *fmt, ...) {
|
||||||
struct connection *conn = MG_CONN_2_CONN(c);
|
struct connection *conn = MG_CONN_2_CONN(c);
|
||||||
struct iobuf *io = &conn->ns_conn->send_iobuf;
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int len, n, iolen;
|
int len;
|
||||||
char *p;
|
char mem[IOBUF_SIZE], *buf = mem;
|
||||||
|
|
||||||
terminate_headers(c);
|
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);
|
va_start(ap, fmt);
|
||||||
len = ns_vprintf(conn->ns_conn, fmt, ap);
|
len = ns_avprintf(&buf, sizeof(mem), fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
// Recalculate pointer p because of potential realloc within iobuf_append
|
if (len > 0) {
|
||||||
p = io->buf + iolen;
|
write_chunk((struct connection *) conn, buf, len);
|
||||||
|
}
|
||||||
// Record size
|
if (buf != mem && buf != NULL) {
|
||||||
n = mg_snprintf(p, 7, "%X", len);
|
free(buf);
|
||||||
p[n] = ' ';
|
}
|
||||||
|
|
||||||
// Write terminating new line
|
|
||||||
mg_write(c, "\r\n", 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MONGOOSE_NO_WEBSOCKET) || !defined(MONGOOSE_NO_AUTH)
|
#if !defined(MONGOOSE_NO_WEBSOCKET) || !defined(MONGOOSE_NO_AUTH)
|
||||||
|
Loading…
Reference in New Issue
Block a user