Skip to content

proper fix for #230: on secure, only pass the requested number of bytes to the parsers #239

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

Merged
merged 2 commits into from
Feb 27, 2018
Merged
Changes from all commits
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
14 changes: 9 additions & 5 deletions ws4py/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,12 @@ def once(self):
logger.debug("WebSocket is already terminated")
return False
try:
b = self.sock.recv(self.reading_buffer_size)
b = b''
if self._is_secure:
b += self._get_from_pending()
if not b:
b = self._get_from_pending()
if not b and not self.buf:
b = self.sock.recv(self.reading_buffer_size)
if not b and not self.buf:
return False
self.buf += b
except (socket.error, OSError, pyOpenSSLError) as e:
Expand All @@ -403,9 +405,11 @@ def once(self):
# process as much as we can
# the process will stop either if there is no buffer left
# or if the stream is closed
if not self.process(self.buf):
# only pass the requested number of bytes, leave the rest in the buffer
requested = self.reading_buffer_size
if not self.process(self.buf[:requested]):
return False
self.buf = b""
self.buf = self.buf[requested:]

return True

Expand Down