From 1d6ae409f6ad393557e6ed5e3c2cfb4a5dccf773 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 8 Jun 2021 20:17:53 +0200 Subject: [PATCH] count expenses when sending files --- copyparty/httpcli.py | 4 +++- copyparty/util.py | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index dd80a7b6..a5112595 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -41,6 +41,7 @@ class HttpCli(object): self.ip = conn.addr[0] self.addr = conn.addr # type: tuple[str, int] self.args = conn.args + self.is_mp = conn.is_mp self.auth = conn.auth # type: AuthSrv self.ico = conn.ico self.thumbcli = conn.thumbcli @@ -1162,7 +1163,8 @@ class HttpCli(object): if use_sendfile: remains = sendfile_kern(lower, upper, f, self.s) else: - remains = sendfile_py(lower, upper, f, self.s) + actor = self.conn if self.is_mp else None + remains = sendfile_py(lower, upper, f, self.s, actor) if remains > 0: logmsg += " \033[31m" + unicode(upper - remains) + "\033[0m" diff --git a/copyparty/util.py b/copyparty/util.py index 9b714c12..1e58f273 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -859,7 +859,7 @@ def hashcopy(actor, fin, fout): if is_mp: actor.workload += 1 if actor.workload > 2 ** 31: - actor.workload = 100 # prevent overflow + actor.workload = 100 tlen += len(buf) hashobj.update(buf) @@ -871,12 +871,17 @@ def hashcopy(actor, fin, fout): return tlen, hashobj.hexdigest(), digest_b64 -def sendfile_py(lower, upper, f, s): +def sendfile_py(lower, upper, f, s, actor=None): remains = upper - lower f.seek(lower) while remains > 0: + if actor: + actor.workload += 1 + if actor.workload > 2 ** 31: + actor.workload = 100 + # time.sleep(0.01) - buf = f.read(min(4096, remains)) + buf = f.read(min(1024 * 32, remains)) if not buf: return remains