Skip to content

Commit

Permalink
Showing 3 changed files with 26 additions and 5 deletions.
20 changes: 20 additions & 0 deletions spec/std/http/web_socket_spec.cr
Original file line number Diff line number Diff line change
@@ -9,6 +9,10 @@ private def assert_text_packet(packet, size, final = false)
assert_packet packet, HTTP::WebSocket::Protocol::Opcode::TEXT, size, final: final
end

private def assert_binary_packet(packet, size, final = false)
assert_packet packet, HTTP::WebSocket::Protocol::Opcode::BINARY, size, final: final
end

private def assert_ping_packet(packet, size, final = false)
assert_packet packet, HTTP::WebSocket::Protocol::Opcode::PING, size, final: final
end
@@ -139,6 +143,22 @@ describe HTTP::WebSocket do
String.new(buffer[0, 1023]).should eq("x" * 1023)
end

it "read very long packet" do
data_slice = Slice(UInt8).new(10 + 0x010000)
header = packet(0x82, 127_u8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00)
data_slice.copy_from(header, 10)

data = data_slice.pointer(data_slice.bytesize)

io = PointerIO.new(pointerof(data))
ws = HTTP::WebSocket::Protocol.new(io)

buffer = Slice(UInt8).new(0x010000)

result = ws.receive(buffer)
assert_binary_packet result, 0x010000, final: true
end

it "can read a close packet" do
data = packet(0x88, 0x00)
io = PointerIO.new(pointerof(data))
10 changes: 5 additions & 5 deletions src/http/web_socket/protocol.cr
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ class HTTP::WebSocket::Protocol
@mask = uninitialized UInt8[4]
@mask_offset = 0
@opcode = Opcode::CONTINUATION
@remaining = 0
@remaining = 0_u64
@masked = !!masked
end

@@ -177,13 +177,13 @@ class HTTP::WebSocket::Protocol
end

private def read_size
size = (@header[1] & 0x7f_u8).to_i
size = (@header[1] & 0x7f_u8).to_u64
if size == 126
size = 0
size = 0_u64
2.times { size <<= 8; size += @io.read_byte.not_nil! }
elsif size == 127
size = 0
4.times { size <<= 8; size += @io.read_byte.not_nil! }
size = 0_u64
8.times { size <<= 8; size += @io.read_byte.not_nil! }
end
size
end
1 change: 1 addition & 0 deletions src/math/libm.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% if flag?(:linux) || flag?(:freebsd) %}
@[Link("m")]
{% end %}

lib LibM
# ## To be uncommented once LLVM is updated
# LLVM binary operations

0 comments on commit d493f0e

Please sign in to comment.