Commit Diff


commit - 2af18508d34e9c770455b438ce36492c91a28119
commit + c058ae64828249f46fbba71edc14fa4e0bea9dca
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 - 7ec6252605df7be2d15b441b35d72f16bc1f8680
blob + 00e4e3a88ba3e1a60ff1538fc4304e36df640792
--- 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 - a76d4ffce3d5b5ebcf828a8dc15495bedb7d3b44
blob + ba97f82beea096c33de8a5be8444b95b282b3942
--- libexec/got-fetch-pack/got-fetch-pack.c
+++ libexec/got-fetch-pack/got-fetch-pack.c
@@ -25,6 +25,7 @@
 #include <stdint.h>
 #include <errno.h>
 #include <limits.h>
+#include <poll.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -367,7 +368,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)
@@ -595,7 +597,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) {
@@ -626,7 +629,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) {
@@ -648,7 +652,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)
@@ -673,7 +677,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) {
@@ -682,7 +687,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) {
@@ -695,7 +701,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) {
@@ -706,7 +713,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) {
@@ -731,7 +739,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 - 7b40464990e4153f3a1019f63dfda9cf5ba69855
blob + 3aff91faa19fba80b86263b1b2e3c9dc46873bc9
--- libexec/got-send-pack/got-send-pack.c
+++ libexec/got-send-pack/got-send-pack.c
@@ -24,6 +24,7 @@
 #include <stdint.h>
 #include <errno.h>
 #include <limits.h>
+#include <poll.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -360,7 +361,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)
@@ -547,7 +549,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) {
@@ -560,7 +562,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) {