bpo-35934: Add socket.create_server() utility function (GH-11784)

This commit is contained in:
Giampaolo Rodola 2019-04-09 00:34:02 +02:00 committed by GitHub
parent 58721a9030
commit eb7e29f2a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 289 additions and 88 deletions

View file

@ -60,21 +60,13 @@ class FunctionalTestCaseMixin:
else:
addr = ('127.0.0.1', 0)
sock = socket.socket(family, socket.SOCK_STREAM)
sock = socket.create_server(addr, family=family, backlog=backlog)
if timeout is None:
raise RuntimeError('timeout is required')
if timeout <= 0:
raise RuntimeError('only blocking sockets are supported')
sock.settimeout(timeout)
try:
sock.bind(addr)
sock.listen(backlog)
except OSError as ex:
sock.close()
raise ex
return TestThreadedServer(
self, sock, server_prog, timeout, max_clients)