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

Method ssl_io_loop

Lib/test/test_ssl.py:2339–2371  ·  view source on GitHub ↗
(self, sock, incoming, outgoing, func, *args, **kwargs)

Source from the content-addressed store, hash-verified

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)

Callers 3

test_bio_handshakeMethod · 0.95
test_transport_eofMethod · 0.95

Calls 7

funcFunction · 0.70
getMethod · 0.45
readMethod · 0.45
sendallMethod · 0.45
recvMethod · 0.45
writeMethod · 0.45
write_eofMethod · 0.45

Tested by

no test coverage detected