From: danw Date: Tue, 3 Mar 1998 23:20:03 +0000 (+0000) Subject: read() in a loop, not all at once, in case packets get split up X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/commitdiff_plain/8cf1531d386d618516247f3bb99836b2bdcdd27a read() in a loop, not all at once, in case packets get split up --- diff --git a/update/sendrecv.c b/update/sendrecv.c index bc3c7458..289007ad 100644 --- a/update/sendrecv.c +++ b/update/sendrecv.c @@ -79,6 +79,7 @@ int send_string(int conn, char *buf, size_t len) int recv_string(int conn, char **buf, size_t *len) { char tmp[4]; + int size, more; if (read(conn, tmp, 4) != 4) { @@ -98,7 +99,14 @@ int recv_string(int conn, char **buf, size_t *len) fail(conn, ENOMEM, "reading string"); return ENOMEM; } - if (read(conn, *buf, *len) != *len) + for (size = 0; size < *len; size += more) + { + more = read(conn, *buf + size, *len - size); + if (!more) + break; + } + + if (size != *len) { free(buf); fail(conn, errno, "reading string");