Code

client: Let client_recv() read a full response.
authorSebastian Harl <sh@tokkee.org>
Thu, 5 Dec 2013 17:26:16 +0000 (18:26 +0100)
committerSebastian Harl <sh@tokkee.org>
Thu, 5 Dec 2013 17:26:16 +0000 (18:26 +0100)
… and block if necessary. There is no reason that a client should handle
partial responses.

src/client/sock.c

index f4f4c556e82012c99927c721fe98697933c939d0..b3be6157996fe7002661b783db2c055d7a382e45 100644 (file)
@@ -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));