1
0
mirror of https://github.com/moparisthebest/sslh synced 2024-11-14 13:15:02 -05:00

Let defer_write accumulate data

This commit is contained in:
Ondřej Kuzník 2013-09-23 23:30:32 +01:00 committed by Yves Rutschle
parent 708c3b0177
commit c5cd91d92c

View File

@ -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 */ /* Store some data to write to the queue later */
int defer_write(struct queue *q, void* data, int data_size) int defer_write(struct queue *q, void* data, int data_size)
{ {
char *p;
if (verbose) if (verbose)
fprintf(stderr, "**** writing defered on fd %d\n", q->fd); fprintf(stderr, "**** writing defered on fd %d\n", q->fd);
q->defered_data = malloc(data_size);
q->begin_defered_data = q->defered_data; p = realloc(q->defered_data, q->defered_data_size + data_size);
q->defered_data_size = data_size; if (!p) {
memcpy(q->defered_data, data, data_size); 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; return 0;
} }