MCPcopy Create free account
hub / github.com/microsoft/debugpy / create_server

Function create_server

src/debugpy/common/sockets.py:62–92  ·  view source on GitHub ↗

Return a local server socket listening on the given port.

(host, port=0, backlog=socket.SOMAXCONN, timeout=None)

Source from the content-addressed store, hash-verified

60 return host, port
61
62def create_server(host, port=0, backlog=socket.SOMAXCONN, timeout=None):
63 """Return a local server socket listening on the given port."""
64
65 assert backlog > 0
66 if host is None:
67 host = get_default_localhost()
68 if port is None:
69 port = 0
70 ipv6 = host.count(":") > 1
71
72 try:
73 server = _new_sock(ipv6)
74 if port != 0:
75 # If binding to a specific port, make sure that the user doesn't have
76 # to wait until the OS times out the socket to be able to use that port
77 # again.if the server or the adapter crash or are force-killed.
78 if sys.platform == "win32":
79 server.setsockopt(socket.SOL_SOCKET, socket.SO_EXCLUSIVEADDRUSE, 1)
80 else:
81 try:
82 server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
83 except (AttributeError, OSError): # pragma: no cover
84 pass # Not available everywhere
85 server.bind((host, port))
86 if timeout is not None:
87 server.settimeout(timeout)
88 server.listen(backlog)
89 except Exception: # pragma: no cover
90 server.close()
91 raise
92 return server
93
94
95def create_client(ipv6=False):

Callers 1

serveFunction · 0.85

Calls 5

get_default_localhostFunction · 0.85
_new_sockFunction · 0.85
listenMethod · 0.80
countMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…