MCPcopy Index your code
hub / github.com/fabioz/PyDev.Debugger / get_socket_names

Function get_socket_names

_pydev_bundle/pydev_localhost.py:37–60  ·  view source on GitHub ↗
(n_sockets, close=False)

Source from the content-addressed store, hash-verified

35
36
37def get_socket_names(n_sockets, close=False):
38 socket_names = []
39 sockets = []
40 for _ in range(n_sockets):
41 if IS_JYTHON:
42 # Although the option which would be pure java *should* work for Jython, the socket being returned is still 0
43 # (i.e.: it doesn't give the local port bound, only the original port, which was 0).
44 from java.net import ServerSocket
45
46 sock = ServerSocket(0)
47 socket_name = get_localhost(), sock.getLocalPort()
48 else:
49 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
50 sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
51 sock.bind((get_localhost(), 0))
52 socket_name = sock.getsockname()
53
54 sockets.append(sock)
55 socket_names.append(socket_name)
56
57 if close:
58 for s in sockets:
59 s.close()
60 return socket_names
61
62
63def get_socket_name(close=False):

Callers 4

get_free_addressesMethod · 0.90
get_free_addressesMethod · 0.90
add_command_line_argsMethod · 0.90
get_socket_nameFunction · 0.85

Calls 3

get_localhostFunction · 0.85
appendMethod · 0.45
closeMethod · 0.45

Tested by 3

get_free_addressesMethod · 0.72
get_free_addressesMethod · 0.72
add_command_line_argsMethod · 0.72