Skip to content

Commit

Permalink
Better handling of EOFError.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed May 5, 2019
1 parent c0bc417 commit 6ab8e9c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/async/websocket/frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ def pack(payload)
end

def read(stream)
buffer = stream.read(2) or raise EOFError
unless buffer = stream.read(2)
return nil
end

first, second = buffer.unpack("CC")

@fin = !!(first & 0b1000_0000)
Expand Down
8 changes: 5 additions & 3 deletions lib/async/websocket/framer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ def flush
def read_frame
frame = Frame.new

frame.read(@stream)

return frame
if frame.read(@stream)
return frame
else
return nil
end
end

def write_frame(frame)
Expand Down

0 comments on commit 6ab8e9c

Please sign in to comment.