Commit Diff


commit - b5a26c03810ac28af0ecc814931f3a23e6d4e1ff
commit + 2af18508d34e9c770455b438ce36492c91a28119
blob - 8f7e6fc6016a235ad21bdb871cd462f6715956a3
blob + 1a06f90da0e0f607b8dd36099d6752a91fab5dc3
--- lib/pkt.c
+++ lib/pkt.c
@@ -24,21 +24,25 @@
 
 #include "got_error.h"
 #include "got_lib_pkt.h"
+#include "got_lib_poll.h"
 
+#define GOT_PKT_TIMEOUT	30
+
 const struct got_error *
 got_pkt_readn(ssize_t *off, int fd, void *buf, size_t n)
 {
-	ssize_t r;
+	const struct got_error *err;
+	size_t len;
 
-	*off = 0;
-	while (*off != n) {
-		r = read(fd, buf + *off, n - *off);
-		if (r == -1)
-			return got_error_from_errno("read");
-		if (r == 0)
-			return got_error(GOT_ERR_EOF);
-		*off += r;
-	}
+	err = got_poll_read_full_timeout(fd, &len, buf, n, n,
+	    GOT_PKT_TIMEOUT);
+	if (err)
+		return err;
+
+	/* XXX size_t -> ssize_t */
+	if (len > SSIZE_MAX)
+		return got_error(GOT_ERR_RANGE);
+	*off = len;
 	return NULL;
 }