From 85302af03f6dd6ee3174f56497f1c5fea7194a7c Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 3 Jan 2016 10:49:05 +1100 Subject: [PATCH] Decrement timeout in read_cs_length --- src/ckpool.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index 58cb831a..f2c6054a 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -555,24 +555,36 @@ static void add_bufline(connsock_t *cs, const char *readbuf, const int len) static int read_cs_length(connsock_t *cs, float *timeout, int len) { + tv_t start, now; int ret = len; + float diff; + + tv_time(&start); while (cs->bufofs < len) { char readbuf[PAGESIZE]; int readlen; + if (*timeout < 0) { + LOGDEBUG("Timed out in read_cs_length"); + ret = 0; + break; + } ret = wait_read_select(cs->fd, *timeout); if (ret < 1) - goto out; + break; readlen = len - cs->bufofs; if (readlen >= PAGESIZE) readlen = PAGESIZE - 4; ret = recv(cs->fd, readbuf, readlen, MSG_DONTWAIT); if (ret < 1) - goto out; + break; add_bufline(cs, readbuf, ret); + tv_time(&now); + diff = tvdiff(&now, &start); + copy_tv(&start, &now); + *timeout -= diff; } -out: return ret; }