Skip to content

Improve SSL performance by avoiding SSLWantReadError exception and using much faster checks whenever possible #629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests
  • Loading branch information
taras committed Sep 9, 2024
commit 26ede3c893f226bf2516cf966bbf70ca5eff3c54
8 changes: 6 additions & 2 deletions uvloop/sslproto.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ cdef class SSLProtocol:
return

cdef:
Py_ssize_t last_bytes_read = -1
Py_ssize_t total_bytes_read = 0
Py_buffer pybuf
bint pybuf_initialized = False
Expand Down Expand Up @@ -762,7 +763,8 @@ cdef class SSLProtocol:
app_buffer_size - total_bytes_read,
PyBUF_WRITE)

total_bytes_read += <Py_ssize_t>self._sslobj_read(app_buffer_size, app_buffer)
last_bytes_read = <Py_ssize_t>self._sslobj_read(app_buffer_size, app_buffer)
total_bytes_read += last_bytes_read

# User buffer may not fit all available data.
# In such case we schedule _do_read to run again later
Expand All @@ -783,7 +785,9 @@ cdef class SSLProtocol:
if total_bytes_read > 0:
self._app_protocol_buffer_updated(total_bytes_read)

if self._incoming.eof:
# SSLObject.read() may return 0 instead of throwing SSLWantReadError
# This indicates that we reached EOF
if last_bytes_read == 0:
# close_notify
self._call_eof_received()
self._start_shutdown()
Expand Down