commit - dcb64fea5fbc0fb5f5cd1947bef3b5d09e266a79
commit + bed0038563e7b63afa004a00b5c3d1c41a9a733b
blob - c4d5d83a73cd53d7437213cdf349daaec168facd
blob + 8e79a1447fe4c445015e4b247a0181fa9d3583ea
--- libexec/got-send-pack/Makefile
+++ libexec/got-send-pack/Makefile
PROG= got-send-pack
SRCS= got-send-pack.c error.c inflate.c object_parse.c \
- path.c privsep.c sha1.c pkt.c gitproto.c
+ path.c privsep.c sha1.c pkt.c gitproto.c ratelimit.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
LDADD = -lutil -lz
blob - bec42fbe983ba0d87334fee8b88459e849fbc337
blob + 11c0b2dbe393420ad16b7edafd58d2091f9c1c8e
--- libexec/got-send-pack/got-send-pack.c
+++ libexec/got-send-pack/got-send-pack.c
#include "got_lib_pack.h"
#include "got_lib_pkt.h"
#include "got_lib_gitproto.h"
+#include "got_lib_ratelimit.h"
#ifndef nitems
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
};
static const struct got_error *
-send_upload_progress(struct imsgbuf *ibuf, off_t bytes)
+send_upload_progress(struct imsgbuf *ibuf, off_t bytes,
+ struct got_ratelimit *rl)
{
+ const struct got_error *err = NULL;
+ int elapsed = 0;
+
+ if (rl) {
+ err = got_ratelimit_check(&elapsed, rl);
+ if (err || !elapsed)
+ return err;
+ }
+
if (imsg_compose(ibuf, GOT_IMSG_SEND_UPLOAD_PROGRESS, 0, 0, -1,
&bytes, sizeof(bytes)) == -1)
return got_error_from_errno(
unsigned char buf[8192];
ssize_t r, w;
off_t wtotal = 0;
+ struct got_ratelimit rl;
if (lseek(packfd, 0L, SEEK_SET) == -1)
return got_error_from_errno("lseek");
+ got_ratelimit_init(&rl, 0, 500);
+
for (;;) {
r = read(packfd, buf, sizeof(buf));
if (r == -1)
if (w != r)
return got_error(GOT_ERR_IO);
wtotal += w;
- err = send_upload_progress(ibuf, wtotal);
+ err = send_upload_progress(ibuf, wtotal, &rl);
if (err)
return err;
}
- return NULL;
+ return send_upload_progress(ibuf, wtotal, NULL);
}
static const struct got_error *