Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/hackney_ws.erl
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,11 @@ handle_active_data(SocketData, #ws_data{buffer = Buffer, owner = Owner, active =
end, Frames),
%% Handle active mode
case Active of
once when Frames =:= [] ->
%% Only part of a frame has arrived: keep reading until
%% a whole frame can be delivered.
_ = set_socket_active(Data2, once),
{keep_state, Data2};
once ->
_ = set_socket_active(Data2, false),
{keep_state, Data2#ws_data{active = false}};
Expand Down
12 changes: 12 additions & 0 deletions test/hackney_ws_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ ws_integration_test_() ->
fun() -> test_ping_pong(WsUrl) end},
{"Active mode once",
fun() -> test_active_once(WsUrl) end},
{"Active mode once with a frame split across reads",
fun() -> test_active_once_split_frame(WsUrl) end},
{"Active mode true",
fun() -> test_active_true(WsUrl) end}
]
Expand Down Expand Up @@ -209,6 +211,16 @@ test_ping_pong(WsUrl) ->
?assertMatch({ok, pong}, Result),
hackney:ws_close(Ws).

test_active_once_split_frame(WsUrl) ->
{ok, Ws} = hackney:ws_connect(WsUrl, [{active, once}]),
ok = hackney:ws_send(Ws, {text, <<"large:1048576">>}),
receive
{hackney_ws, Ws, {binary, Bin}} -> ?assertEqual(1048576, byte_size(Bin))
after 3000 ->
?assert(false)
end,
hackney:ws_close(Ws).

test_active_once(WsUrl) ->
{ok, Ws} = hackney:ws_connect(WsUrl, [{active, once}]),

Expand Down