mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-22 06:53:46 +00:00
Probe both TCP and UDP ports in interoperability tests
This commit is contained in:
+13
-3
@@ -118,9 +118,19 @@ def udp_case(proxy_port, origin_port):
|
|||||||
|
|
||||||
|
|
||||||
def free_port():
|
def free_port():
|
||||||
with socket.socket() as sock:
|
# TCP and UDP have separate port reservations, especially on Windows.
|
||||||
sock.bind(("127.0.0.1", 0))
|
# Probe both while holding the TCP socket so a TCP-only free port cannot
|
||||||
return sock.getsockname()[1]
|
# select a reserved or occupied UDP endpoint.
|
||||||
|
for _ in range(100):
|
||||||
|
with socket.socket() as tcp, socket.socket(type=socket.SOCK_DGRAM) as udp:
|
||||||
|
tcp.bind(("127.0.0.1", 0))
|
||||||
|
port = tcp.getsockname()[1]
|
||||||
|
try:
|
||||||
|
udp.bind(("127.0.0.1", port))
|
||||||
|
except OSError:
|
||||||
|
continue
|
||||||
|
return port
|
||||||
|
raise RuntimeError("could not find a free TCP/UDP port")
|
||||||
|
|
||||||
|
|
||||||
def wait_ready(process, port):
|
def wait_ready(process, port):
|
||||||
|
|||||||
Reference in New Issue
Block a user