Update WebSocket compress code. Increase the chunk to 32k for reading.

Update send data to the client, when the pmce compression extension was accepted
send all the data at once.
This commit is contained in:
jvelilla
2016-10-27 09:51:40 -03:00
parent 4c912912a6
commit 4a21dcd2d6
3 changed files with 52 additions and 41 deletions

View File

@@ -90,6 +90,7 @@ feature -- Websocket execution
-- Called after the WebSocket connection is closed.
do
ws.put_error ("Connection closed")
ws.send (Connection_close_frame, "")
end
feature -- HTML Resource

View File

@@ -68,9 +68,9 @@ feature -- Access
end
if accept_client_max_window_bits then
if client_max_window_bits > 0 then
Result.append_character (';')
Result.append ("client_max_window_bits")
if client_max_window_bits > 0 then
Result.append_character ('=')
Result.append_integer (client_max_window_bits)
end

View File

@@ -265,6 +265,7 @@ feature -- Response!
retried: BOOLEAN
l_message: STRING_8
l_opcode: NATURAL_32
l_remaning_len: INTEGER
do
l_message := a_message
if attached accepted_offer and then not on_handshake then
@@ -303,7 +304,10 @@ feature -- Response!
end
socket.put_string_8_noexception (l_header_message)
if not socket.was_error then
l_chunk_size := 16_384 -- 16K TODO: see if we should make it customizable.
if attached accepted_offer and then not on_handshake then
socket.put_string_8_noexception (l_message)
else
l_chunk_size := 0x8000 --16_384 -- 16K TODO: see if we should make it customizable.
if l_message_count < l_chunk_size then
socket.put_string_8_noexception (l_message)
else
@@ -315,7 +319,12 @@ feature -- Response!
debug ("ws")
print ("Sending chunk " + (i + 1).out + " -> " + (i + l_chunk_size).out +" / " + l_message_count.out + "%N")
end
l_remaning_len := l_message_count - i*l_chunk_size
if l_remaning_len < l_chunk_size then
l_chunk := a_message.substring (i + 1, l_message_count.min (i + l_remaning_len))
else
l_chunk := a_message.substring (i + 1, l_message_count.min (i + l_chunk_size))
end
socket.put_string_8_noexception (l_chunk)
if l_chunk.count < l_chunk_size then
l_chunk_size := 0
@@ -327,6 +336,7 @@ feature -- Response!
end
end
end
end
else
-- FIXME: what should be done on rescue?
@@ -563,7 +573,7 @@ feature -- Response!
Result.report_error (protocol_error, "All frames sent from client to server are masked!")
end
if Result.is_valid then
l_chunk_size := 0x4000 -- 16 K
l_chunk_size := 0x8000 -- 16 K
if l_payload_len > {INTEGER_32}.max_value.to_natural_64 then
-- Issue .. to big to store in STRING
-- FIXME !!!
@@ -602,7 +612,7 @@ feature -- Response!
if attached accepted_offer then
-- Uncompress data.
Result.append_raw_data_chop (l_chunk, l_bytes_read, l_remaining_len = 0)
if Result.is_fin and then attached Result.raw_data as l_raw_data then
if Result.is_fin and then attached Result.raw_data as l_raw_data and then l_remaining_len = 0 then
Result.append_payload_data_chop (uncompress_string (l_raw_data), Result.raw_data_length.to_integer_32, l_remaining_len = 0)
end
else
@@ -875,21 +885,21 @@ feature -- PCME
---- l_array := string_to_array (l_string)
---- l_byte := byte_array (l_array)
-- -- TODO add logic to compute window size based on extension negotiation.
-- TODO add logic to compute window size based on extension negotiation.
-- create di.string_stream_with_size (l_string, {WEB_SOCKET_PCME_CONSTANTS}.default_chunk_size)
create di.string_stream_with_size (l_string, {WEB_SOCKET_PMCE_CONSTANTS}.default_chunk_size)
-- -- Append 4 octects 0x00 0x00 0xff 0xff to the tail of the paiload message
-- l_string.append_character ((0x00).to_character_8)
-- l_string.append_character ((0x00).to_character_8)
-- l_string.append_character ((0xff).to_character_8)
-- l_string.append_character ((0xff).to_character_8)
-- Result := di.to_string_with_options (-{WEB_SOCKET_PCME_CONSTANTS}.default_window_size)
-- Append 4 octects 0x00 0x00 0xff 0xff to the tail of the paiload message
l_string.append_character ((0x00).to_character_8)
l_string.append_character ((0x00).to_character_8)
l_string.append_character ((0xff).to_character_8)
l_string.append_character ((0xff).to_character_8)
Result := di.to_string_with_options (-{WEB_SOCKET_PMCE_CONSTANTS}.default_window_size)
-- debug ("ws")
-- print ("%NBytes uncompresses:" + di.total_bytes_uncompressed.out)
-- end
Result := do_uncompress (a_string)
debug ("ws")
print ("%NBytes uncompresses:" + di.total_bytes_uncompressed.out)
end
-- Result := do_uncompress (a_string)
end
@@ -933,14 +943,14 @@ feature -- PCME
debug ("ws")
print ("%NBegin compresses:" + a_string.count.out)
end
-- -- TODO add logic to compute window size based on extension negotiation.
-- create Result.make_empty
-- create dc.string_stream_with_size (Result, {WEB_SOCKET_PCME_CONSTANTS}.default_chunk_size)
-- dc.mark_sync_flush
-- dc.put_string_with_options (a_string, {ZLIB_CONSTANTS}.Z_default_compression, -{WEB_SOCKET_PCME_CONSTANTS}.default_window_size, {WEB_SOCKET_PCME_CONSTANTS}.default_value_memory, {ZLIB_CONSTANTS}.z_default_strategy.to_integer_32)
-- Result := Result.substring (1, Result.count - 4)
-- TODO add logic to compute window size based on extension negotiation.
create Result.make_empty
create dc.string_stream_with_size (Result, {WEB_SOCKET_PMCE_CONSTANTS}.default_chunk_size)
dc.mark_full_flush
dc.put_string_with_options (a_string, {ZLIB_CONSTANTS}.Z_default_compression, -{WEB_SOCKET_PMCE_CONSTANTS}.default_window_size, {WEB_SOCKET_PMCE_CONSTANTS}.default_value_memory, {ZLIB_CONSTANTS}.z_default_strategy.to_integer_32)
Result := Result.substring (1, Result.count - 4)
Result := do_compress (a_string)
-- Result := do_compress (a_string)
end