From c9f0858c560889fc5fb6a61deffcd963a7732343 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 2 Jan 2016 00:45:19 +1100 Subject: [PATCH] Fixes? --- src/ckpool.c | 7 +++---- src/connector.c | 16 +++++++--------- src/libckpool.c | 12 ------------ src/libckpool.h | 2 -- 4 files changed, 10 insertions(+), 27 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index e7b698ea..2f49936a 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -739,13 +739,12 @@ int write_cs(connsock_t *cs, const char *buf, int len) ret = write_socket(cs->fd, buf, len); goto out; } - compsize = round_up_page(len + 12); - dest = ckalloc(compsize); - compsize -= 12; + dest = ckalloc(len + 12); /* Do compression here */ + compsize = len; ret = compress((Bytef *)dest + 12, &compsize, (Bytef *)buf, len); if (ret != Z_OK) { - LOGWARNING("Failed to gz compress in write_cs, writing uncompressed"); + LOGINFO("Failed to gz compress in write_cs, writing uncompressed"); ret = write_socket(cs->fd, buf, len); goto out; } diff --git a/src/connector.c b/src/connector.c index cb1d240d..dd173478 100644 --- a/src/connector.c +++ b/src/connector.c @@ -1003,29 +1003,27 @@ static void send_client(cdata_t *cdata, const int64_t id, char *buf) /* Does this client accept compressed data? Only compress if it's * larger than one MTU. */ - if (client->gz && len > 1492) { - unsigned long compsize; + if (client->gz) { + unsigned long compsize, decompsize = len; + char *dest = ckalloc(len + 12); uint32_t msglen; - char *dest; int ret; - compsize = round_up_page(len + 12); - dest = ckalloc(compsize); - compsize -= 12; + compsize = len; ret = compress((Bytef *)dest + 12, &compsize, (Bytef *)buf, len); if (unlikely(ret != Z_OK)) { - LOGWARNING("Failed to gz compress in send_client, got %d sending uncompressed", ret); + LOGINFO("Failed to gz compress in send_client, got %d sending uncompressed", ret); free(dest); goto out; } - LOGDEBUG("Sending client message compressed %lu from %d", compsize, len); + LOGDEBUG("Sending client message compressed %lu from %lu", compsize, decompsize); /* Copy gz magic header */ sprintf(dest, gzip_magic); /* Copy compressed message length */ msglen = htole32(compsize); memcpy(dest + 4, &msglen, 4); /* Copy decompressed message length */ - msglen = htole32(len); + msglen = htole32(decompsize); memcpy(dest + 8, &msglen, 4); len = compsize + 12; free(buf); diff --git a/src/libckpool.c b/src/libckpool.c index 2e78d330..a0557a71 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -1389,18 +1389,6 @@ void *_ckzalloc(size_t len, const char *file, const char *func, const int line) return ptr; } -/* Round up to the nearest page size for efficient malloc */ -size_t round_up_page(size_t len) -{ - int rem = len % PAGESIZE; - - if (rem) - len += PAGESIZE - rem; - return len; -} - - - /* Adequate size s==len*2 + 1 must be alloced to use this variant */ void __bin2hex(void *vs, const void *vp, size_t len) { diff --git a/src/libckpool.h b/src/libckpool.h index 10c18248..9d8ba341 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -531,8 +531,6 @@ void trail_slash(char **buf); void *_ckalloc(size_t len, const char *file, const char *func, const int line); void *json_ckalloc(size_t size); void *_ckzalloc(size_t len, const char *file, const char *func, const int line); -size_t round_up_page(size_t len); - extern const int hex2bin_tbl[]; void __bin2hex(void *vs, const void *vp, size_t len); void *bin2hex(const void *vp, size_t len);