MCPcopy Index your code
hub / github.com/python/cpython / tcp_server

Method tcp_server

Lib/test/test_asyncio/test_ssl.py:102–132  ·  view source on GitHub ↗
(self, server_prog, *,
                   family=socket.AF_INET,
                   addr=None,
                   timeout=support.SHORT_TIMEOUT,
                   backlog=1,
                   max_clients=10)

Source from the content-addressed store, hash-verified

100 super().tearDown()
101
102 def tcp_server(self, server_prog, *,
103 family=socket.AF_INET,
104 addr=None,
105 timeout=support.SHORT_TIMEOUT,
106 backlog=1,
107 max_clients=10):
108
109 if addr is None:
110 if family == getattr(socket, "AF_UNIX", None):
111 with tempfile.NamedTemporaryFile() as tmp:
112 addr = tmp.name
113 else:
114 addr = ('127.0.0.1', 0)
115
116 sock = socket.socket(family, socket.SOCK_STREAM)
117
118 if timeout is None:
119 raise RuntimeError('timeout is required')
120 if timeout <= 0:
121 raise RuntimeError('only blocking sockets are supported')
122 sock.settimeout(timeout)
123
124 try:
125 sock.bind(addr)
126 sock.listen(backlog)
127 except OSError as ex:
128 sock.close()
129 raise ex
130
131 return TestThreadedServer(
132 self, sock, server_prog, timeout, max_clients)
133
134 def tcp_client(self, client_prog,
135 family=socket.AF_INET,

Calls 6

socketMethod · 0.80
TestThreadedServerClass · 0.70
settimeoutMethod · 0.45
bindMethod · 0.45
listenMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected