(self, server_prog, *,
family=socket.AF_INET,
addr=None,
timeout=support.SHORT_TIMEOUT,
backlog=1,
max_clients=10)
| 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, |
no test coverage detected