From: Sebastian Harl Date: Thu, 5 Dec 2013 17:26:16 +0000 (+0100) Subject: client: Let client_recv() read a full response. X-Git-Tag: sysdb-0.1.0~327 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f9589ac43999831fe995da5b1cb61a6db07967a3;p=sysdb.git client: Let client_recv() read a full response. … and block if necessary. There is no reason that a client should handle partial responses. --- 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));