From f9589ac43999831fe995da5b1cb61a6db07967a3 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Thu, 5 Dec 2013 18:26:16 +0100 Subject: [PATCH] client: Let client_recv() read a full response. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit … and block if necessary. There is no reason that a client should handle partial responses. --- src/client/sock.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/client/sock.c b/src/client/sock.c index f4f4c55..b3be615 100644 --- a/src/client/sock.c +++ b/src/client/sock.c @@ -183,11 +183,13 @@ sdb_client_recv(sdb_client_t *client, while (42) { ssize_t status; + /* XXX: use select */ + errno = 0; status = sdb_strbuf_read(buf, client->fd, req); if (status < 0) { if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) - break; + continue; return status; } else if (! status) /* EOF */ @@ -213,6 +215,12 @@ sdb_client_recv(sdb_client_t *client, break; } + if (total != req) { + /* unexpected EOF; clear partially read data */ + sdb_strbuf_skip(buf, data_offset, sdb_strbuf_len(buf)); + return 0; + } + if (rstatus != UINT32_MAX) /* remove status,len */ sdb_strbuf_skip(buf, data_offset, 2 * sizeof(rstatus)); -- 2.30.2