Commit Diff


commit - 6fefa431eee865872ebe9a069e18cba946baf1df
commit + 0fb910a41f7587983405793e780968c72b3f4197
blob - 8295c80b38111178704802e1cfa5b090781c7ed5
blob + 10d25af037a4ca56ce7ad9e2ad296bccd2281c17
--- lib/got_lib_pkt.h
+++ lib/got_lib_pkt.h
@@ -18,11 +18,12 @@
 #define GOT_PKT_MAX	65536
 
 const struct got_error *got_pkt_readn(ssize_t *off, int fd, void *buf,
-    size_t n);
+    size_t n, int timeout);
 const struct got_error *got_pkt_flushpkt(int fd, int chattygot);
 const struct got_error *got_pkt_readlen(int *len, const char *str, int chattygot);
-const struct got_error *got_pkt_readhdr(int *datalen, int fd, int chattygot);
+const struct got_error *got_pkt_readhdr(int *datalen, int fd, int chattygot,
+    int timeout);
 const struct got_error *got_pkt_readpkt(int *outlen, int fd, char *buf,
-    int buflen, int chattygot);
+    int buflen, int chattygot, int timeout);
 const struct got_error *got_pkt_writepkt(int fd, char *buf, int nbuf,
     int chattygot);
blob - 1a06f90da0e0f607b8dd36099d6752a91fab5dc3
blob + 4766c8fa97b29e1042f1c64af20a4354a8b0e505
--- lib/pkt.c
+++ lib/pkt.c
@@ -26,16 +26,15 @@
 #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)
+got_pkt_readn(ssize_t *off, int fd, void *buf, size_t n,
+    int timeout)
 {
 	const struct got_error *err;
 	size_t len;
 
 	err = got_poll_read_full_timeout(fd, &len, buf, n, n,
-	    GOT_PKT_TIMEOUT);
+	    timeout);
 	if (err)
 		return err;
 
@@ -91,7 +90,7 @@ got_pkt_readlen(int *len, const char *str, int chattyg
  * of data which follows.
  */
 const struct got_error *
-got_pkt_readhdr(int *datalen, int fd, int chattygot)
+got_pkt_readhdr(int *datalen, int fd, int chattygot, int timeout)
 {
 	static const struct got_error *err;
 	char lenstr[4];
@@ -100,7 +99,7 @@ got_pkt_readhdr(int *datalen, int fd, int chattygot)
 
 	*datalen = 0;
 
-	err = got_pkt_readn(&r, fd, lenstr, 4);
+	err = got_pkt_readn(&r, fd, lenstr, 4, timeout);
 	if (err)
 		return err;
 	if (r == 0) {
@@ -125,20 +124,21 @@ got_pkt_readhdr(int *datalen, int fd, int chattygot)
 }
 
 const struct got_error *
-got_pkt_readpkt(int *outlen, int fd, char *buf, int buflen, int chattygot)
+got_pkt_readpkt(int *outlen, int fd, char *buf, int buflen, int chattygot,
+    int timeout)
 {
 	const struct got_error *err = NULL;
 	int datalen, i;
 	ssize_t n;
 
-	err = got_pkt_readhdr(&datalen, fd, chattygot);
+	err = got_pkt_readhdr(&datalen, fd, chattygot, timeout);
 	if (err)
 		return err;
 
 	if (datalen > buflen)
 		return got_error(GOT_ERR_NO_SPACE);
 
-	err = got_pkt_readn(&n, fd, buf, datalen);
+	err = got_pkt_readn(&n, fd, buf, datalen, timeout);
 	if (err)
 		return err;
 	if (n != datalen)
blob - e03137e6800e1939de4210d638076544517c3445
blob + a3aeb1c2501fd8cce22b87ef6768bad08a6fe599
--- lib/serve.c
+++ lib/serve.c
@@ -49,6 +49,12 @@
 #ifndef nitems
 #define nitems(_a)	(sizeof((_a)) / sizeof((_a)[0]))
 #endif
+
+/*
+ * Number of seconds until we give up trying to read more
+ * data from the client connection.
+ */
+static const int timeout = 60;
 
 static const struct got_capability read_capabilities[] = {
 	{ GOT_CAPA_AGENT, "got/" GOT_VERSION_STR },
@@ -791,7 +797,8 @@ serve_read(int infd, int outfd, int gotd_sock, const c
 	while (curstate != STATE_DONE) {
 		int n;
 		buf[0] = '\0';
-		err = got_pkt_readpkt(&n, infd, buf, sizeof(buf), chattygot);
+		err = got_pkt_readpkt(&n, infd, buf, sizeof(buf), chattygot,
+		    timeout);
 		if (err)
 			goto done;
 		if (n == 0) {
@@ -1261,7 +1268,8 @@ serve_write(int infd, int outfd, int gotd_sock, const 
 	while (curstate != STATE_EXPECT_PACKFILE) {
 		int n;
 		buf[0] = '\0';
-		err = got_pkt_readpkt(&n, infd, buf, sizeof(buf), chattygot);
+		err = got_pkt_readpkt(&n, infd, buf, sizeof(buf), chattygot,
+		    timeout);
 		if (err)
 			goto done;
 		if (n == 0) {
blob - 4e20977276b1e47ce59ae8184bdc6c63ad1cab08
blob + 7410ec56e191326b2f490dfc214b907874ff03ca
--- libexec/got-fetch-pack/got-fetch-pack.c
+++ libexec/got-fetch-pack/got-fetch-pack.c
@@ -24,6 +24,7 @@
 #include <errno.h>
 #include <imsg.h>
 #include <limits.h>
+#include <poll.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -368,7 +369,8 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1,
 		goto done;
 	}
 	while (1) {
-		err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
+		err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot,
+		    INFTIM);
 		if (err)
 			goto done;
 		if (n == 0)
@@ -596,7 +598,8 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1,
 		struct got_object_id common_id;
 
 		/* The server should ACK the object IDs we need. */
-		err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
+		err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot,
+		    INFTIM);
 		if (err)
 			goto done;
 		if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
@@ -627,7 +630,8 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1,
 	}
 
 	if (nhave == 0) {
-		err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
+		err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot,
+		    INFTIM);
 		if (err)
 			goto done;
 		if (n != 4 || strncmp(buf, "NAK\n", n) != 0) {
@@ -649,7 +653,7 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1,
 		int datalen = -1;
 
 		if (have_sidebands) {
-			err = got_pkt_readhdr(&datalen, fd, chattygot);
+			err = got_pkt_readhdr(&datalen, fd, chattygot, INFTIM);
 			if (err)
 				goto done;
 			if (datalen <= 0)
@@ -674,7 +678,8 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1,
 			datalen--; /* sideband ID has been read */
 			if (buf[0] == GOT_SIDEBAND_PACKFILE_DATA) {
 				/* Read packfile data. */
-				err = got_pkt_readn(&r, fd, buf, datalen);
+				err = got_pkt_readn(&r, fd, buf, datalen,
+				    INFTIM);
 				if (err)
 					goto done;
 				if (r != datalen) {
@@ -683,7 +688,8 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1,
 					goto done;
 				}
 			} else if (buf[0] == GOT_SIDEBAND_PROGRESS_INFO) {
-				err = got_pkt_readn(&r, fd, buf, datalen);
+				err = got_pkt_readn(&r, fd, buf, datalen,
+				    INFTIM);
 				if (err)
 					goto done;
 				if (r != datalen) {
@@ -696,7 +702,8 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1,
 					goto done;
 				continue;
 			} else if (buf[0] == GOT_SIDEBAND_ERROR_INFO) {
-				err = got_pkt_readn(&r, fd, buf, datalen);
+				err = got_pkt_readn(&r, fd, buf, datalen,
+				    INFTIM);
 				if (err)
 					goto done;
 				if (r != datalen) {
@@ -707,7 +714,8 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1,
 				err = fetch_error(buf, r);
 				goto done;
 			} else if (buf[0] == 'A') {
-				err = got_pkt_readn(&r, fd, buf, datalen);
+				err = got_pkt_readn(&r, fd, buf, datalen,
+				    INFTIM);
 				if (err)
 					goto done;
 				if (r != datalen) {
@@ -732,7 +740,7 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1,
 			}
 		} else {
 			/* No sideband channel. Every byte is packfile data. */
-			err = got_pkt_readn(&r, fd, buf, sizeof buf);
+			err = got_pkt_readn(&r, fd, buf, sizeof buf, INFTIM);
 			if (err)
 				goto done;
 			if (r <= 0)
blob - dc7a261465f7dbccf70213d2cc4f78255d7ea53a
blob + 7c7c29553882ad9c792d99d2dc1c9cdda83597de
--- libexec/got-send-pack/got-send-pack.c
+++ libexec/got-send-pack/got-send-pack.c
@@ -25,6 +25,7 @@
 #include <errno.h>
 #include <imsg.h>
 #include <limits.h>
+#include <poll.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -362,7 +363,8 @@ send_pack(int fd, struct got_pathlist_head *refs,
 		return got_error(GOT_ERR_SEND_EMPTY);
 
 	while (1) {
-		err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
+		err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot,
+		    INFTIM);
 		if (err)
 			goto done;
 		if (n == 0)
@@ -549,7 +551,7 @@ send_pack(int fd, struct got_pathlist_head *refs,
 			goto done;
 	}
 
-	err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
+	err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot, INFTIM);
 	if (err)
 		goto done;
 	if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
@@ -562,7 +564,8 @@ send_pack(int fd, struct got_pathlist_head *refs,
 	}
 
 	while (nsent > 0) {
-		err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
+		err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot,
+		    INFTIM);
 		if (err)
 			goto done;
 		if (n < 3) {