From c5cd91d92c26184055312cd6b77c95f69e759c72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Kuzn=C3=ADk?= Date: Mon, 23 Sep 2013 23:30:32 +0100 Subject: [PATCH] Let defer_write accumulate data --- common.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/common.c b/common.c index 2f008d5..9f7edaa 100644 --- a/common.c +++ b/common.c @@ -161,12 +161,20 @@ int connect_addr(struct addrinfo *addr, int fd_from, const char* cnx_name) /* Store some data to write to the queue later */ int defer_write(struct queue *q, void* data, int data_size) { + char *p; if (verbose) fprintf(stderr, "**** writing defered on fd %d\n", q->fd); - q->defered_data = malloc(data_size); - q->begin_defered_data = q->defered_data; - q->defered_data_size = data_size; - memcpy(q->defered_data, data, data_size); + + p = realloc(q->defered_data, q->defered_data_size + data_size); + if (!p) { + perror("realloc"); + exit(1); + } + + q->defered_data = q->begin_defered_data = p; + p += q->defered_data_size; + q->defered_data_size += data_size; + memcpy(p, data, data_size); return 0; }