mirror of
https://github.com/3proxy/3proxy.git
synced 2026-10-15 16:15:49 +08:00
tests: run the half-close case on Windows again
The previous commit lets a half-closed client be written to on Windows
too, so the case left out there is back.
This reverts commit 5d1cdf8.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9f46558d0b
commit
18d3ff101a
@ -1,7 +1,6 @@
|
|||||||
"""The port mappers: tcppm forwards a TCP port, udppm a UDP one."""
|
"""The port mappers: tcppm forwards a TCP port, udppm a UDP one."""
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
import sys
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -65,44 +64,38 @@ def run(t):
|
|||||||
|
|
||||||
t.stop_all()
|
t.stop_all()
|
||||||
|
|
||||||
# WSAPoll reports a hang-up once the peer has half-closed, not once
|
# A client which shuts down its sending side still gets the whole answer,
|
||||||
# both sides are shut down as poll() does elsewhere, and sockmap() takes
|
# even when it reads slowly: the server has finished and closed by then,
|
||||||
# it for a client it can no longer write to: not covered there yet.
|
# and the rest of the answer waits in the proxy's buffer and the kernel's.
|
||||||
if sys.platform == "win32":
|
listener = socket.socket()
|
||||||
t.skip("a half-closed client gets the whole answer (not on Windows)")
|
listener.bind(("127.0.0.1", 0))
|
||||||
else:
|
listener.listen(1)
|
||||||
# A client which shuts down its sending side still gets the whole answer,
|
threading.Thread(target=halfclose_origin, args=(listener,), daemon=True).start()
|
||||||
# even when it reads slowly: the server has finished and closed by then,
|
halfclosed = t.free_port()
|
||||||
# and the rest of the answer waits in the proxy's buffer and the kernel's.
|
t.start("portmap_halfclose", f"""
|
||||||
listener = socket.socket()
|
log
|
||||||
listener.bind(("127.0.0.1", 0))
|
auth none
|
||||||
listener.listen(1)
|
tcppm {halfclosed} 127.0.0.1 {listener.getsockname()[1]}
|
||||||
threading.Thread(target=halfclose_origin, args=(listener,), daemon=True).start()
|
""", ports=[halfclosed])
|
||||||
halfclosed = t.free_port()
|
s = socket.socket()
|
||||||
t.start("portmap_halfclose", f"""
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 32768)
|
||||||
log
|
s.settimeout(30)
|
||||||
auth none
|
got = 0
|
||||||
tcppm {halfclosed} 127.0.0.1 {listener.getsockname()[1]}
|
try:
|
||||||
""", ports=[halfclosed])
|
s.connect(("127.0.0.1", halfclosed))
|
||||||
s = socket.socket()
|
s.sendall(b"request")
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 32768)
|
s.shutdown(socket.SHUT_WR)
|
||||||
s.settimeout(30)
|
time.sleep(1)
|
||||||
got = 0
|
while True:
|
||||||
try:
|
d = s.recv(65536)
|
||||||
s.connect(("127.0.0.1", halfclosed))
|
if not d:
|
||||||
s.sendall(b"request")
|
break
|
||||||
s.shutdown(socket.SHUT_WR)
|
got += len(d)
|
||||||
time.sleep(1)
|
except OSError:
|
||||||
while True:
|
pass
|
||||||
d = s.recv(65536)
|
s.close()
|
||||||
if not d:
|
listener.close()
|
||||||
break
|
t.eq(HALFCLOSE_SIZE, got, "a half-closed client reading slowly gets the whole answer")
|
||||||
got += len(d)
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
s.close()
|
|
||||||
listener.close()
|
|
||||||
t.eq(HALFCLOSE_SIZE, got, "a half-closed client reading slowly gets the whole answer")
|
|
||||||
|
|
||||||
t.stop_all()
|
t.stop_all()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user