mirror of
https://github.com/9001/copyparty.git
synced 2025-08-18 01:22:13 -06:00
fix dualstack on lo
This commit is contained in:
parent
03f53f6392
commit
2cb1f50370
|
@ -2,6 +2,7 @@
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
import errno
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
|
@ -81,8 +82,7 @@ class HttpSrv(object):
|
||||||
self.bans: dict[str, int] = {}
|
self.bans: dict[str, int] = {}
|
||||||
self.aclose: dict[str, int] = {}
|
self.aclose: dict[str, int] = {}
|
||||||
|
|
||||||
self.ip = ""
|
self.bound: set[tuple[str, int]] = set()
|
||||||
self.port = 0
|
|
||||||
self.name = "hsrv" + nsuf
|
self.name = "hsrv" + nsuf
|
||||||
self.mutex = threading.Lock()
|
self.mutex = threading.Lock()
|
||||||
self.stopping = False
|
self.stopping = False
|
||||||
|
@ -142,7 +142,11 @@ class HttpSrv(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def set_netdevs(self, netdevs: dict[str, Netdev]) -> None:
|
def set_netdevs(self, netdevs: dict[str, Netdev]) -> None:
|
||||||
self.nm = NetMap([self.ip], netdevs)
|
ips = set()
|
||||||
|
for ip, _ in self.bound:
|
||||||
|
ips.add(ip)
|
||||||
|
|
||||||
|
self.nm = NetMap(list(ips), netdevs)
|
||||||
|
|
||||||
def start_threads(self, n: int) -> None:
|
def start_threads(self, n: int) -> None:
|
||||||
self.tp_nthr += n
|
self.tp_nthr += n
|
||||||
|
@ -184,12 +188,13 @@ class HttpSrv(object):
|
||||||
sck.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
sck.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||||
sck.settimeout(None) # < does not inherit, ^ opts above do
|
sck.settimeout(None) # < does not inherit, ^ opts above do
|
||||||
|
|
||||||
self.ip, self.port = sck.getsockname()[:2]
|
ip, port = sck.getsockname()[:2]
|
||||||
self.srvs.append(sck)
|
self.srvs.append(sck)
|
||||||
|
self.bound.add((ip, port))
|
||||||
self.nclimax = math.ceil(self.args.nc * 1.0 / nlisteners)
|
self.nclimax = math.ceil(self.args.nc * 1.0 / nlisteners)
|
||||||
Daemon(
|
Daemon(
|
||||||
self.thr_listen,
|
self.thr_listen,
|
||||||
"httpsrv-n{}-listen-{}-{}".format(self.nid or "0", self.ip, self.port),
|
"httpsrv-n{}-listen-{}-{}".format(self.nid or "0", ip, port),
|
||||||
(sck,),
|
(sck,),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -282,6 +287,16 @@ class HttpSrv(object):
|
||||||
if self.stopping:
|
if self.stopping:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if (
|
||||||
|
ex.errno == errno.EINVAL
|
||||||
|
and ip == "0.0.0.0"
|
||||||
|
and ("::", port) in self.bound
|
||||||
|
):
|
||||||
|
t = "accept({}): {} -- probably due to dualstack; terminating ({}, {})"
|
||||||
|
self.log(self.name, t.format(fno, ex, ip, port), c=6)
|
||||||
|
srv_sck.close()
|
||||||
|
return
|
||||||
|
|
||||||
self.log(self.name, "accept({}): {}".format(fno, ex), c=6)
|
self.log(self.name, "accept({}): {}".format(fno, ex), c=6)
|
||||||
time.sleep(0.02)
|
time.sleep(0.02)
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue