|
|
@ -555,7 +555,7 @@ static int read_cs_length(connsock_t *cs, float *timeout, int len) |
|
|
|
int ret = len; |
|
|
|
int ret = len; |
|
|
|
|
|
|
|
|
|
|
|
while (cs->buflen < len) { |
|
|
|
while (cs->buflen < len) { |
|
|
|
char readbuf[PAGESIZE] = {}; |
|
|
|
char readbuf[PAGESIZE]; |
|
|
|
|
|
|
|
|
|
|
|
ret = wait_read_select(cs->fd, *timeout); |
|
|
|
ret = wait_read_select(cs->fd, *timeout); |
|
|
|
if (ret < 1) |
|
|
|
if (ret < 1) |
|
|
@ -629,7 +629,7 @@ static int read_gz_line(connsock_t *cs, float *timeout) |
|
|
|
buflen = cs->buflen; |
|
|
|
buflen = cs->buflen; |
|
|
|
cs->buf = dest; |
|
|
|
cs->buf = dest; |
|
|
|
dest = NULL; |
|
|
|
dest = NULL; |
|
|
|
ret = cs->buflen = decompsize - 1; |
|
|
|
ret = cs->buflen = decompsize; |
|
|
|
if (buflen) |
|
|
|
if (buflen) |
|
|
|
add_bufline(cs, buf, buflen); |
|
|
|
add_bufline(cs, buf, buflen); |
|
|
|
out: |
|
|
|
out: |
|
|
@ -732,23 +732,20 @@ int write_cs(connsock_t *cs, const char *buf, int len) |
|
|
|
unsigned long compsize, decompsize = len; |
|
|
|
unsigned long compsize, decompsize = len; |
|
|
|
char *dest = NULL; |
|
|
|
char *dest = NULL; |
|
|
|
uint32_t msglen; |
|
|
|
uint32_t msglen; |
|
|
|
int ret = -1; |
|
|
|
int ret; |
|
|
|
|
|
|
|
|
|
|
|
/* Connsock doesn't expect gz compressed messages */ |
|
|
|
/* Connsock doesn't expect gz compressed messages */ |
|
|
|
if (!cs->gz || len <= 1492) { |
|
|
|
if (!cs->gz || len <= 1492) |
|
|
|
ret = write_socket(cs->fd, buf, len); |
|
|
|
return write_socket(cs->fd, buf, len); |
|
|
|
goto out; |
|
|
|
compsize = round_up_page(len + 12); |
|
|
|
} |
|
|
|
dest = alloca(compsize); |
|
|
|
dest = ckalloc(len + 12); |
|
|
|
|
|
|
|
/* Do compression here */ |
|
|
|
/* Do compression here */ |
|
|
|
compsize = len; |
|
|
|
compsize -= 12; |
|
|
|
ret = compress((Bytef *)dest + 12, &compsize, (Bytef *)buf, len); |
|
|
|
ret = compress((Bytef *)dest + 12, &compsize, (Bytef *)buf, len); |
|
|
|
if (ret != Z_OK) { |
|
|
|
if (ret != Z_OK) { |
|
|
|
LOGINFO("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); |
|
|
|
return write_socket(cs->fd, buf, len); |
|
|
|
goto out; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
LOGDEBUG("Writing connsock message compressed %lu from %lu", compsize, decompsize); |
|
|
|
|
|
|
|
/* Copy gz magic header */ |
|
|
|
/* Copy gz magic header */ |
|
|
|
sprintf(dest, gzip_magic); |
|
|
|
sprintf(dest, gzip_magic); |
|
|
|
/* Copy compressed message length */ |
|
|
|
/* Copy compressed message length */ |
|
|
@ -758,13 +755,12 @@ int write_cs(connsock_t *cs, const char *buf, int len) |
|
|
|
msglen = htole32(decompsize); |
|
|
|
msglen = htole32(decompsize); |
|
|
|
memcpy(dest + 8, &msglen, 4); |
|
|
|
memcpy(dest + 8, &msglen, 4); |
|
|
|
len = compsize + 12; |
|
|
|
len = compsize + 12; |
|
|
|
|
|
|
|
LOGDEBUG("Writing connsock message compressed %d from %lu", len, decompsize); |
|
|
|
ret = write_socket(cs->fd, dest, len); |
|
|
|
ret = write_socket(cs->fd, dest, len); |
|
|
|
if (ret == len) |
|
|
|
if (ret == len) |
|
|
|
ret = decompsize; |
|
|
|
ret = decompsize; |
|
|
|
else |
|
|
|
else |
|
|
|
ret = -1; |
|
|
|
ret = -1; |
|
|
|
out: |
|
|
|
|
|
|
|
free(dest); |
|
|
|
|
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|