Browse Source

Fixes?

master
Con Kolivas 9 years ago
parent
commit
c9f0858c56
  1. 7
      src/ckpool.c
  2. 16
      src/connector.c
  3. 12
      src/libckpool.c
  4. 2
      src/libckpool.h

7
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;
}

16
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);

12
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)
{

2
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);

Loading…
Cancel
Save