(self, sock, incoming, outgoing, func, *args, **kwargs)
| 2337 | self.assertIs(ss._sslobj.context, ctx2) |
| 2338 | |
| 2339 | def ssl_io_loop(self, sock, incoming, outgoing, func, *args, **kwargs): |
| 2340 | # A simple IO loop. Call func(*args) depending on the error we get |
| 2341 | # (WANT_READ or WANT_WRITE) move data between the socket and the BIOs. |
| 2342 | timeout = kwargs.get('timeout', support.SHORT_TIMEOUT) |
| 2343 | count = 0 |
| 2344 | for _ in support.busy_retry(timeout): |
| 2345 | errno = None |
| 2346 | count += 1 |
| 2347 | try: |
| 2348 | ret = func(*args) |
| 2349 | except ssl.SSLError as e: |
| 2350 | if e.errno not in (ssl.SSL_ERROR_WANT_READ, |
| 2351 | ssl.SSL_ERROR_WANT_WRITE): |
| 2352 | raise |
| 2353 | errno = e.errno |
| 2354 | # Get any data from the outgoing BIO irrespective of any error, and |
| 2355 | # send it to the socket. |
| 2356 | buf = outgoing.read() |
| 2357 | sock.sendall(buf) |
| 2358 | # If there's no error, we're done. For WANT_READ, we need to get |
| 2359 | # data from the socket and put it in the incoming BIO. |
| 2360 | if errno is None: |
| 2361 | break |
| 2362 | elif errno == ssl.SSL_ERROR_WANT_READ: |
| 2363 | buf = sock.recv(32768) |
| 2364 | if buf: |
| 2365 | incoming.write(buf) |
| 2366 | else: |
| 2367 | incoming.write_eof() |
| 2368 | if support.verbose: |
| 2369 | sys.stdout.write("Needed %d calls to complete %s().\n" |
| 2370 | % (count, func.__name__)) |
| 2371 | return ret |
| 2372 | |
| 2373 | def test_bio_handshake(self): |
| 2374 | sock = socket.socket(socket.AF_INET) |
no test coverage detected