From 11023ecfec71833681d2407e9034aadd952aac2e Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 29 Apr 2015 19:47:14 +1000 Subject: [PATCH] Use non blocking reads in read_socket_line --- src/ckpool.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index 4688c59d..eb3885c6 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -530,35 +530,34 @@ int read_socket_line(connsock_t *cs, const int timeout) eom = strchr(cs->buf, '\n'); } + ret = wait_read_select(fd, timeout); + if (ret < 1) { + if (!ret) + LOGDEBUG("Select timed out in read_socket_line"); + else { + if (cs->ckp->proxy) + LOGINFO("Select failed in read_socket_line"); + else + LOGERR("Select failed in read_socket_line"); + } + goto out; + } while (42) { char readbuf[PAGESIZE] = {}; int backoff = 1; char *newbuf; - ret = wait_read_select(fd, eom ? 0 : timeout); - if (ret < 1) { - if (eom) - break; - if (!ret) - LOGDEBUG("Select timed out in read_socket_line"); - else { - if (cs->ckp->proxy) - LOGNOTICE("Select failed in read_socket_line"); - else - LOGERR("Select failed in read_socket_line"); - } - goto out; - } - ret = recv(fd, readbuf, PAGESIZE - 4, 0); + ret = recv(fd, readbuf, PAGESIZE - 4, MSG_DONTWAIT); if (ret < 1) { /* Closed socket after valid message */ - if (eom) + if (eom || !ret || errno == EAGAIN || errno == EWOULDBLOCK) { + ret = 0; break; + } if (cs->ckp->proxy) - LOGNOTICE("Failed to recv in read_socket_line"); + LOGINFO("Failed to recv in read_socket_line"); else LOGERR("Failed to recv in read_socket_line"); - ret = -1; goto out; } buflen = cs->bufofs + ret + 1;