From 4ae647b1dd261accf6c26d113287778db25cad0a Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 10 Jun 2014 21:32:32 +1000 Subject: [PATCH] Empty the buffer on empty socket --- src/ckpool.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ckpool.c b/src/ckpool.c index 9ce02a14..41772d2b 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -124,6 +124,11 @@ bool ping_main(ckpool_t *ckp) return true; } +void empty_buffer(connsock_t *cs) +{ + cs->buflen = cs->bufofs = 0; +} + /* 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. */ @@ -345,6 +350,7 @@ json_t *json_rpc_call(connsock_t *cs, const char *rpc_req) LOGWARNING("JSON decode failed(%d): %s", err_val.line, err_val.text); out_empty: empty_socket(cs->fd); + empty_buffer(cs); if (!val) { /* Assume that a failed request means the socket will be closed * and reopen it */