Skip to content

Commit

Permalink
fix for issue Lawouach#230
Browse files Browse the repository at this point in the history
  • Loading branch information
Michiel, Jeroen committed Jan 19, 2018
1 parent 0a76787 commit 1d25512
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 32 deletions.
2 changes: 1 addition & 1 deletion ws4py/framing.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _parsing(self):
some_bytes = buf[:self.payload_length]

self.body = some_bytes
yield
yield len(some_bytes)-len(buf)

def mask(self, data):
"""
Expand Down
12 changes: 10 additions & 2 deletions ws4py/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,20 @@ def receiver(self):
utf8validator = Utf8Validator()
running = True
frame = None
remaining = 0
while running:
frame = Frame()
while 1:
try:
some_bytes = (yield next(frame.parser))
frame.parser.send(some_bytes)
if remaining<0:
#another message left in the pipeline
some_bytes = (yield remaining)
else:
some_bytes = (yield next(frame.parser))
remaining = frame.parser.send(some_bytes)
if remaining < 0:
#another message is waiting, but we can finish this one
next(frame.parser)
except GeneratorExit:
running = False
break
Expand Down
64 changes: 35 additions & 29 deletions ws4py/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,39 +455,45 @@ def process(self, bytes):
if not bytes and self.reading_buffer_size > 0:
return False

self.reading_buffer_size = s.parser.send(bytes) or DEFAULT_READING_SIZE
while bytes:
self.reading_buffer_size = s.parser.send(bytes) or DEFAULT_READING_SIZE

if s.closing is not None:
logger.debug("Closing message received (%d) '%s'" % (s.closing.code, s.closing.reason))
if not self.server_terminated:
self.close(s.closing.code, s.closing.reason)
if self.reading_buffer_size < 0:
bytes = bytes[self.reading_buffer_size:]
else:
self.client_terminated = True
return False
bytes = b''

if s.closing is not None:
logger.debug("Closing message received (%d) '%s'" % (s.closing.code, s.closing.reason))
if not self.server_terminated:
self.close(s.closing.code, s.closing.reason)
else:
self.client_terminated = True
return False

if s.errors:
for error in s.errors:
logger.debug("Error message received (%d) '%s'" % (error.code, error.reason))
self.close(error.code, error.reason)
s.errors = []
return False
if s.errors:
for error in s.errors:
logger.debug("Error message received (%d) '%s'" % (error.code, error.reason))
self.close(error.code, error.reason)
s.errors = []
return False

if s.has_message:
self.received_message(s.message)
if s.message is not None:
s.message.data = None
s.message = None
return True

if s.pings:
for ping in s.pings:
self._write(s.pong(ping.data))
s.pings = []

if s.pongs:
for pong in s.pongs:
self.ponged(pong)
s.pongs = []
if s.has_message:
self.received_message(s.message)
if s.message is not None:
s.message.data = None
s.message = None
continue

if s.pings:
for ping in s.pings:
self._write(s.pong(ping.data))
s.pings = []

if s.pongs:
for pong in s.pongs:
self.ponged(pong)
s.pongs = []

return True

Expand Down

0 comments on commit 1d25512

Please sign in to comment.