diff --git a/src/ckpool.c b/src/ckpool.c index a5b32411..5c156f0a 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -512,6 +512,10 @@ void empty_buffer(connsock_t *cs) cs->buflen = cs->bufofs = 0; } +/* If there is any cs->buflen it implies a full line was received on the last + * pass through read_socket_line and subsequently processed, leaving + * unprocessed data beyond cs->bufofs. Otherwise a zero buflen means there is + * only unprocessed data of bufos length. */ static void clear_bufline(connsock_t *cs) { if (unlikely(!cs->buf)) @@ -522,8 +526,7 @@ static void clear_bufline(connsock_t *cs) cs->bufofs = cs->buflen; cs->buflen = 0; cs->buf[cs->bufofs] = '\0'; - } else - cs->bufofs = 0; + } } static void add_buflen(connsock_t *cs, const char *readbuf, const int len) @@ -571,7 +574,9 @@ static int recv_available(connsock_t *cs) /* Read from a socket into cs->buf till we get an '\n', converting it to '\0' * and storing how much extra data we've received, to be moved to the beginning - * of the buffer for use on the next receive. */ + * of the buffer for use on the next receive. Returns length of the line if a + * whole line is received, zero if none/some data is received without an EOL + * and -1 on error. */ int read_socket_line(connsock_t *cs, float *timeout) { bool proxy = cs->ckp->proxy; diff --git a/src/generator.c b/src/generator.c index 5de773a8..98a5c185 100644 --- a/src/generator.c +++ b/src/generator.c @@ -1949,11 +1949,8 @@ static void *passthrough_recv(void *arg) * process. Possibly parse parameters sent by upstream pool * here */ if (likely(ret > 0)) { - if (strchr(cs->buf, '\n')) { - LOGDEBUG("Passthrough recv received upstream msg: %s", cs->buf); - send_proc(ckp->connector, cs->buf); - } else - LOGDEBUG("Passthrough recv received partial message"); + LOGDEBUG("Passthrough recv received upstream msg: %s", cs->buf); + send_proc(ckp->connector, cs->buf); } else if (ret < 0) { /* Read failure */ LOGWARNING("Passthrough %d:%s failed to read_socket_line in passthrough_recv, attempting reconnect", @@ -1961,7 +1958,7 @@ static void *passthrough_recv(void *arg) alive = proxi->alive = false; Close(cs->fd); reconnect_generator(ckp); - } else /* Idle, likely no clients */ + } else /* No messages during timeout */ LOGDEBUG("Passthrough %d:%s no messages received", proxi->id, proxi->url); cksem_post(&cs->sem); }