Browse Source

More gracefully handle out of sync/corrupt binary messages by searching memory for EOL instead of strings

master
Con Kolivas 9 years ago
parent
commit
fc6331e279
  1. 12
      src/ckpool.c

12
src/ckpool.c

@ -713,7 +713,7 @@ int read_socket_line(connsock_t *cs, float *timeout)
clear_bufline(cs); clear_bufline(cs);
recv_available(ckp, cs); // Intentionally ignore return value recv_available(ckp, cs); // Intentionally ignore return value
eom = strchr(cs->buf, '\n'); eom = memchr(cs->buf, '\n', cs->bufofs);
tv_time(&start); tv_time(&start);
@ -751,7 +751,7 @@ int read_socket_line(connsock_t *cs, float *timeout)
ret = -1; ret = -1;
goto out; goto out;
} }
eom = strchr(cs->buf, '\n'); eom = memchr(cs->buf, '\n', cs->bufofs);
tv_time(&now); tv_time(&now);
diff = tvdiff(&now, &start); diff = tvdiff(&now, &start);
copy_tv(&start, &now); copy_tv(&start, &now);
@ -764,10 +764,10 @@ int read_socket_line(connsock_t *cs, float *timeout)
ret = eom - cs->buf; ret = eom - cs->buf;
} else } else
*eom = '\0'; *eom = '\0';
cs->buflen = cs->buf + cs->bufofs - eom - 1; if (cs->bufofs > ret + 1) {
if (cs->buflen) cs->buflen = cs->bufofs - ret - 1;
cs->bufofs = eom - cs->buf + 1; cs->bufofs = ret + 1;
else } else
cs->bufofs = 0; cs->bufofs = 0;
out: out:
if (ret < 0) { if (ret < 0) {

Loading…
Cancel
Save