commit - 2af18508d34e9c770455b438ce36492c91a28119
commit + c058ae64828249f46fbba71edc14fa4e0bea9dca
blob - 8295c80b38111178704802e1cfa5b090781c7ed5
blob + 10d25af037a4ca56ce7ad9e2ad296bccd2281c17
--- lib/got_lib_pkt.h
+++ lib/got_lib_pkt.h
#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
#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;
* 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];
*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) {
}
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
#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 },
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) {
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
#include <stdint.h>
#include <errno.h>
#include <limits.h>
+#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
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)
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) {
}
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) {
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)
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) {
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) {
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) {
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) {
}
} 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
#include <stdint.h>
#include <errno.h>
#include <limits.h>
+#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
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)
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) {
}
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) {