commit - 0d039490032e7afdddb00a59c0e6240c9b1a4dfa
commit + ec1fc282066c81c2ae67cedff55b819ff8886cd8
blob - ba97f82beea096c33de8a5be8444b95b282b3942
blob + 18ab5b10d5415ba969c09b492b674e9da5a53871
--- 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.