diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2014-04-29 08:03:28 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2014-04-29 08:03:28 (GMT) |
commit | b4bebdafe354f68a9b952772da109cccd73f6577 (patch) | |
tree | 939614adab3160c1c9d54ba6975b326a2cdd31b9 /Lib/test | |
parent | 727a463aa624931a89c796bfa4fe5711e2c403ff (diff) | |
download | cpython-b4bebdafe354f68a9b952772da109cccd73f6577.zip cpython-b4bebdafe354f68a9b952772da109cccd73f6577.tar.gz cpython-b4bebdafe354f68a9b952772da109cccd73f6577.tar.bz2 |
Issue #20951: SSLSocket.send() now raises either SSLWantReadError or SSLWantWriteError on a non-blocking socket if the operation would block. Previously, it would return 0.
Patch by Nikolaus Rath.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_ssl.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py index a23d263..f72fb15 100644 --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -2547,6 +2547,36 @@ else: s.write(b"over\n") s.close() + def test_nonblocking_send(self): + server = ThreadedEchoServer(CERTFILE, + certreqs=ssl.CERT_NONE, + ssl_version=ssl.PROTOCOL_TLSv1, + cacerts=CERTFILE, + chatty=True, + connectionchatty=False) + with server: + s = ssl.wrap_socket(socket.socket(), + server_side=False, + certfile=CERTFILE, + ca_certs=CERTFILE, + cert_reqs=ssl.CERT_NONE, + ssl_version=ssl.PROTOCOL_TLSv1) + s.connect((HOST, server.port)) + s.setblocking(False) + + # If we keep sending data, at some point the buffers + # will be full and the call will block + buf = bytearray(8192) + def fill_buffer(): + while True: + s.send(buf) + self.assertRaises((ssl.SSLWantWriteError, + ssl.SSLWantReadError), fill_buffer) + + # Now read all the output and discard it + s.setblocking(True) + s.close() + def test_handshake_timeout(self): # Issue #5103: SSL handshake must respect the socket timeout server = socket.socket(socket.AF_INET) |