commit - f9723081c18b7e34cbf6bb15792c3965670deaab
commit + 2b1d417da7256f4a2ca5a1e7d20a9ba901dec893
blob - 7410ec56e191326b2f490dfc214b907874ff03ca
blob + 5dcffb2885a13005b4a036fbdd3148bafb5410d6
--- libexec/got-fetch-pack/got-fetch-pack.c
+++ libexec/got-fetch-pack/got-fetch-pack.c
#include "got_lib_privsep.h"
#include "got_lib_pack.h"
#include "got_lib_pkt.h"
+#include "got_lib_poll.h"
#include "got_lib_gitproto.h"
#include "got_lib_ratelimit.h"
char hashstr[SHA1_DIGEST_STRING_LENGTH];
struct got_object_id *have, *want;
int is_firstpkt = 1, nref = 0, refsz = 16;
- int i, n, nwant = 0, nhave = 0, acked = 0;
+ int i, n, nwant = 0, nhave = 0, acked = 0, eof = 0;
off_t packsz = 0, last_reported_packsz = 0;
char *id_str = NULL, *default_id_str = NULL, *refname = NULL;
char *server_capabilities = NULL, *my_capabilities = NULL;
strstr(my_capabilities, GOT_CAPA_SIDE_BAND_64K) != NULL)
have_sidebands = 1;
- while (1) {
+ while (!eof) {
ssize_t r = 0;
int datalen = -1;
}
} else {
/* No sideband channel. Every byte is packfile data. */
- err = got_pkt_readn(&r, fd, buf, sizeof buf, INFTIM);
- if (err)
- goto done;
- if (r <= 0)
- break;
+ size_t n = 0;
+ err = got_poll_read_full_timeout(fd, &n,
+ buf, sizeof buf, 1, INFTIM);
+ if (err) {
+ if (err->code != GOT_ERR_EOF)
+ goto done;
+ r = 0;
+ eof = 1;
+ } else
+ r = n;
}
/*
* keep SHA1_DIGEST_LENGTH bytes buffered and avoid mixing
* those bytes into our SHA1 checksum computation until we
* know for sure that additional pack file data bytes follow.
- *
- * We can assume r > 0 since otherwise the loop would exit.
*/
if (r < SHA1_DIGEST_LENGTH) {
if (sha1_buf_len < SHA1_DIGEST_LENGTH) {
/* Buffer potential checksum bytes. */
memcpy(sha1_buf + sha1_buf_len, buf, r);
sha1_buf_len += r;
- } else {
+ } else if (r > 0) {
/*
* Mix in previously buffered bytes which
* are not part of the checksum after all.