Skip to content

Commit

Permalink
proper fix for Lawouach#230: on secure, only pass the requested numbe…
Browse files Browse the repository at this point in the history
…r of bytes to the parsers
  • Loading branch information
jmichiel committed Jan 19, 2018
1 parent 0a76787 commit 8f9d068
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions ws4py/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,11 @@ def once(self):
logger.debug("WebSocket is already terminated")
return False
try:
b = self.sock.recv(self.reading_buffer_size)
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 +404,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

0 comments on commit 8f9d068

Please sign in to comment.