diff options
author | Andrey Petrov <shazow@gmail.com> | 2015-05-17 21:32:58 -0700 |
---|---|---|
committer | Andrey Petrov <shazow@gmail.com> | 2015-05-17 21:32:58 -0700 |
commit | 5f3fce4d00c09d582e79b44bdfaf958d76c3a99f (patch) | |
tree | e8df873728926610de4fa5e56aae735f4c92bafc | |
parent | 0d2f46ebe60b5f094bb28137d9ab62adc01cbe58 (diff) | |
parent | 7f55d0dc0be2bcd66d10104678aa098ecf09372c (diff) | |
download | urllib3-5f3fce4d00c09d582e79b44bdfaf958d76c3a99f.tar.gz |
Merge pull request #628 from darkrain42/master
Further improvements to pyopenssl sendall()
-rw-r--r-- | urllib3/contrib/pyopenssl.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/urllib3/contrib/pyopenssl.py b/urllib3/contrib/pyopenssl.py index 3d3cd60f..19c5b4ee 100644 --- a/urllib3/contrib/pyopenssl.py +++ b/urllib3/contrib/pyopenssl.py @@ -85,6 +85,14 @@ _openssl_verify = { DEFAULT_SSL_CIPHER_LIST = util.ssl_.DEFAULT_CIPHERS +# OpenSSL will only write 16K at a time +SSL_WRITE_BLOCKSIZE = 16384 + +try: + _ = memoryview + has_memoryview = True +except NameError: + has_memoryview = False orig_util_HAS_SNI = util.HAS_SNI orig_connection_ssl_wrap_socket = connection.ssl_wrap_socket @@ -204,10 +212,12 @@ class WrappedSocket(object): continue def sendall(self, data): + if has_memoryview and not isinstance(data, memoryview): + data = memoryview(data) + total_sent = 0 while total_sent < len(data): - # OpenSSL will only write 16K at once - sent = self._send_until_done(data[total_sent:total_sent+16384]) + sent = self._send_until_done(data[total_sent:total_sent+SSL_WRITE_BLOCKSIZE]) total_sent += sent def shutdown(self): |