Skip to content

Commit

Permalink
Merge pull request #239 from jmichiel/fix_230_2
Browse files Browse the repository at this point in the history
proper fix for #230: on secure, only pass the requested number of bytes to the parsers
  • Loading branch information
Lawouach authored Feb 27, 2018
2 parents c2d9e28 + e566ee3 commit 510cba1
Showing 1 changed file with 9 additions and 5 deletions.
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

0 comments on commit 510cba1

Please sign in to comment.