mirror of
https://github.com/9001/copyparty.git
synced 2025-08-19 18:02:28 -06:00
count expenses when sending files
This commit is contained in:
parent
9d729d3d1a
commit
1d6ae409f6
|
@ -41,6 +41,7 @@ class HttpCli(object):
|
||||||
self.ip = conn.addr[0]
|
self.ip = conn.addr[0]
|
||||||
self.addr = conn.addr # type: tuple[str, int]
|
self.addr = conn.addr # type: tuple[str, int]
|
||||||
self.args = conn.args
|
self.args = conn.args
|
||||||
|
self.is_mp = conn.is_mp
|
||||||
self.auth = conn.auth # type: AuthSrv
|
self.auth = conn.auth # type: AuthSrv
|
||||||
self.ico = conn.ico
|
self.ico = conn.ico
|
||||||
self.thumbcli = conn.thumbcli
|
self.thumbcli = conn.thumbcli
|
||||||
|
@ -1162,7 +1163,8 @@ class HttpCli(object):
|
||||||
if use_sendfile:
|
if use_sendfile:
|
||||||
remains = sendfile_kern(lower, upper, f, self.s)
|
remains = sendfile_kern(lower, upper, f, self.s)
|
||||||
else:
|
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:
|
if remains > 0:
|
||||||
logmsg += " \033[31m" + unicode(upper - remains) + "\033[0m"
|
logmsg += " \033[31m" + unicode(upper - remains) + "\033[0m"
|
||||||
|
|
|
@ -859,7 +859,7 @@ def hashcopy(actor, fin, fout):
|
||||||
if is_mp:
|
if is_mp:
|
||||||
actor.workload += 1
|
actor.workload += 1
|
||||||
if actor.workload > 2 ** 31:
|
if actor.workload > 2 ** 31:
|
||||||
actor.workload = 100 # prevent overflow
|
actor.workload = 100
|
||||||
|
|
||||||
tlen += len(buf)
|
tlen += len(buf)
|
||||||
hashobj.update(buf)
|
hashobj.update(buf)
|
||||||
|
@ -871,12 +871,17 @@ def hashcopy(actor, fin, fout):
|
||||||
return tlen, hashobj.hexdigest(), digest_b64
|
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
|
remains = upper - lower
|
||||||
f.seek(lower)
|
f.seek(lower)
|
||||||
while remains > 0:
|
while remains > 0:
|
||||||
|
if actor:
|
||||||
|
actor.workload += 1
|
||||||
|
if actor.workload > 2 ** 31:
|
||||||
|
actor.workload = 100
|
||||||
|
|
||||||
# time.sleep(0.01)
|
# time.sleep(0.01)
|
||||||
buf = f.read(min(4096, remains))
|
buf = f.read(min(1024 * 32, remains))
|
||||||
if not buf:
|
if not buf:
|
||||||
return remains
|
return remains
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue