mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
Do not use SO_REUSEADDR et all when listening on ephemeral ports (#1064)
This commit is contained in:
parent
1d038201b3
commit
e7fb50add3
1 changed files with 11 additions and 7 deletions
|
|
@ -21,6 +21,17 @@ def create_server(host, port=0, backlog=socket.SOMAXCONN, timeout=None):
|
|||
|
||||
try:
|
||||
server = _new_sock()
|
||||
if port != 0:
|
||||
# If binding to a specific port, make sure that the user doesn't have
|
||||
# to wait until the OS times out the socket to be able to use that port
|
||||
# again.if the server or the adapter crash or are force-killed.
|
||||
if sys.platform == "win32":
|
||||
server.setsockopt(socket.SOL_SOCKET, socket.SO_EXCLUSIVEADDRUSE, 1)
|
||||
else:
|
||||
try:
|
||||
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
except (AttributeError, OSError):
|
||||
pass # Not available everywhere
|
||||
server.bind((host, port))
|
||||
if timeout is not None:
|
||||
server.settimeout(timeout)
|
||||
|
|
@ -38,13 +49,6 @@ def create_client():
|
|||
|
||||
def _new_sock():
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
|
||||
if sys.platform == "win32":
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_EXCLUSIVEADDRUSE, 1)
|
||||
else:
|
||||
try:
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
except (AttributeError, OSError):
|
||||
pass # Not available everywhere
|
||||
|
||||
# Set TCP keepalive on an open socket.
|
||||
# It activates after 1 second (TCP_KEEPIDLE,) of idleness,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue