diff --git a/copyparty/broker_mpw.py b/copyparty/broker_mpw.py index ae4b9fe5..fdfbbe43 100644 --- a/copyparty/broker_mpw.py +++ b/copyparty/broker_mpw.py @@ -35,7 +35,7 @@ class MpWorker(object): signal.signal(signal.SIGINT, self.signal_handler) # instantiate all services here (TODO: inheritance?) - self.httpsrv = HttpSrv(self) + self.httpsrv = HttpSrv(self, True) self.httpsrv.disconnect_func = self.httpdrop # on winxp and some other platforms, @@ -75,7 +75,7 @@ class MpWorker(object): if self.args.log_conn: self.log("%s %s" % addr, "|%sC-qpop" % ("-" * 4,), c="1;30") - + self.httpsrv.accept(sck, addr) with self.mutex: diff --git a/copyparty/httpconn.py b/copyparty/httpconn.py index b505f2dd..cb2162dd 100644 --- a/copyparty/httpconn.py +++ b/copyparty/httpconn.py @@ -35,6 +35,7 @@ class HttpConn(object): self.args = hsrv.args self.auth = hsrv.auth + self.is_mp = hsrv.is_mp self.cert_path = hsrv.cert_path enth = HAVE_PIL and not self.args.no_thumb @@ -174,6 +175,11 @@ class HttpConn(object): self.sr = Unrecv(self.s) while True: + if self.is_mp: + self.workload += 50 + if self.workload >= 2 ** 31: + self.workload = 100 + cli = HttpCli(self) if not cli.run(): return diff --git a/copyparty/httpsrv.py b/copyparty/httpsrv.py index 996bd90d..356d9c58 100644 --- a/copyparty/httpsrv.py +++ b/copyparty/httpsrv.py @@ -35,8 +35,9 @@ class HttpSrv(object): relying on MpSrv for performance (HttpSrv is just plain threads) """ - def __init__(self, broker): + def __init__(self, broker, is_mp=False): self.broker = broker + self.is_mp = is_mp self.args = broker.args self.log = broker.log @@ -84,13 +85,14 @@ class HttpSrv(object): cli = HttpConn(sck, addr, self) with self.mutex: self.clients[cli] = 0 - self.workload += 50 - if not self.workload_thr_alive: - self.workload_thr_alive = True - thr = threading.Thread(target=self.thr_workload) - thr.daemon = True - thr.start() + if self.is_mp: + self.workload += 50 + if not self.workload_thr_alive: + self.workload_thr_alive = True + thr = threading.Thread(target=self.thr_workload) + thr.daemon = True + thr.start() try: if self.args.log_conn: diff --git a/copyparty/util.py b/copyparty/util.py index 5b627f9b..17b91203 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -852,13 +852,14 @@ def yieldfile(fn): def hashcopy(actor, fin, fout): - u32_lim = int((2 ** 31) * 0.9) + is_mp = actor.is_mp hashobj = hashlib.sha512() tlen = 0 for buf in fin: - actor.workload += 1 - if actor.workload > u32_lim: - actor.workload = 100 # prevent overflow + if is_mp: + actor.workload += 1 + if actor.workload > 2 ** 31: + actor.workload = 100 # prevent overflow tlen += len(buf) hashobj.update(buf) diff --git a/tests/util.py b/tests/util.py index 1a24ac2e..eb412008 100644 --- a/tests/util.py +++ b/tests/util.py @@ -116,6 +116,7 @@ class VHttpConn(object): self.addr = ("127.0.0.1", "42069") self.args = args self.auth = auth + self.is_mp = False self.log_func = log self.log_src = "a" self.lf_url = None