diff --git a/ws/session.nim b/ws/session.nim index 10fb6204..904ab2d8 100644 --- a/ws/session.nim +++ b/ws/session.nim @@ -354,28 +354,26 @@ proc recv*( trace "Setting binary flag" let len = min(ws.frame.remainder.int, size - consumed) - if len <= 0: - trace "Nothing left to read, breaking!" - break + if len > 0: + trace "Reading bytes from frame stream", len + let read = await ws.stream.reader.readOnce(addr pbuffer[consumed], len) + if read <= 0: + trace "Didn't read any bytes, breaking" + break - trace "Reading bytes from frame stream", len - let read = await ws.stream.reader.readOnce(addr pbuffer[consumed], len) - if read <= 0: - trace "Didn't read any bytes, breaking" - break + trace "Read data from frame", read - if ws.frame.mask: - trace "Unmasking frame" - # unmask data using offset - mask( - pbuffer.toOpenArray(consumed, (consumed + read) - 1), - ws.frame.maskKey, - ws.frame.consumed.int) + if ws.frame.mask: + trace "Unmasking frame" + # unmask data using offset + mask( + pbuffer.toOpenArray(consumed, (consumed + read) - 1), + ws.frame.maskKey, + ws.frame.consumed.int) - consumed += read - ws.frame.consumed += read.uint64 + consumed += read + ws.frame.consumed += read.uint64 - trace "Read data from frame", read # all has been consumed from the frame # read the next frame if ws.frame.remainder <= 0: