From 7e2280ff2d7573ef3499ac7d1cc0516b3ddd1b51 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 29 Apr 2015 20:06:12 +1000 Subject: [PATCH] Check for eom more carefully in read_socket_line --- src/ckpool.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index eb3885c6..360c4abb 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -530,11 +530,13 @@ int read_socket_line(connsock_t *cs, const int timeout) eom = strchr(cs->buf, '\n'); } - ret = wait_read_select(fd, timeout); + ret = wait_read_select(fd, eom ? 0 : timeout); if (ret < 1) { - if (!ret) + if (!ret) { + if (eom) + goto parse; LOGDEBUG("Select timed out in read_socket_line"); - else { + } else { if (cs->ckp->proxy) LOGINFO("Select failed in read_socket_line"); else @@ -549,11 +551,9 @@ int read_socket_line(connsock_t *cs, const int timeout) ret = recv(fd, readbuf, PAGESIZE - 4, MSG_DONTWAIT); if (ret < 1) { - /* Closed socket after valid message */ - if (eom || !ret || errno == EAGAIN || errno == EWOULDBLOCK) { - ret = 0; + /* No more to read or closed socket after valid message */ + if (eom) break; - } if (cs->ckp->proxy) LOGINFO("Failed to recv in read_socket_line"); else @@ -578,6 +578,7 @@ int read_socket_line(connsock_t *cs, const int timeout) cs->buf[cs->bufofs] = '\0'; eom = strchr(cs->buf, '\n'); } +parse: ret = eom - cs->buf; cs->buflen = cs->buf + cs->bufofs - eom - 1;