Browse Source

Fix end of message parsing logic fail

master
Con Kolivas 11 years ago
parent
commit
76921ce29f
  1. 13
      src/ckpool.c

13
src/ckpool.c

@ -137,6 +137,7 @@ int read_socket_line(connsock_t *cs, int timeout)
if (unlikely(cs->fd < 0)) if (unlikely(cs->fd < 0))
goto out; goto out;
if (unlikely(!cs->buf)) if (unlikely(!cs->buf))
cs->buf = ckzalloc(PAGESIZE); cs->buf = ckzalloc(PAGESIZE);
else if (cs->buflen) { else if (cs->buflen) {
@ -144,9 +145,9 @@ int read_socket_line(connsock_t *cs, int timeout)
memset(cs->buf + cs->buflen, 0, cs->bufofs); memset(cs->buf + cs->buflen, 0, cs->bufofs);
cs->bufofs = cs->buflen; cs->bufofs = cs->buflen;
cs->buflen = 0; cs->buflen = 0;
cs->buf[cs->bufofs] = '\0';
eom = strchr(cs->buf, '\n'); eom = strchr(cs->buf, '\n');
} else }
cs->bufofs = 0;
while (42) { while (42) {
char readbuf[PAGESIZE] = {}; char readbuf[PAGESIZE] = {};
@ -182,11 +183,11 @@ int read_socket_line(connsock_t *cs, int timeout)
} }
ret = eom - cs->buf; ret = eom - cs->buf;
if (eom < cs->buf + cs->bufofs) { cs->buflen = cs->buf + cs->bufofs - eom - 1;
cs->buflen = cs->buf + cs->bufofs - eom - 1; if (cs->buflen)
cs->bufofs = eom - cs->buf + 1; cs->bufofs = eom - cs->buf + 1;
} else else
cs->buflen = cs->bufofs = 0; cs->bufofs = 0;
*eom = '\0'; *eom = '\0';
out: out:
if (ret < 0) { if (ret < 0) {

Loading…
Cancel
Save