Skip to content

Commit

Permalink
fix(config): when get, remove \0 from close_reason_phrase
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed Feb 16, 2024
1 parent 241c477 commit 9f53b72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions c_src/quicer_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@ encode_parm_to_eterm(ErlNifEnv *env,
&& QUICER_PARAM_HANDLE_TYPE_CONN == Type))
{
ERL_NIF_TERM ebin;
if (QUIC_PARAM_CONN_CLOSE_REASON_PHRASE == Param)
{
BufferLength -= 1; // remove \0
}
unsigned char *bin_data = enif_make_new_binary(env, BufferLength, &ebin);
if (!bin_data)
{
Expand Down
8 changes: 5 additions & 3 deletions test/quicer_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,9 @@ tc_getopt(Config) ->
{quic, <<"ping">>, Stm, _} -> ok
end,
ok = quicer:close_connection(Conn),
%% @todo unsupp in msquic, leave it for now
{error, _} = quicer:getopt(Conn, close_reason_phrase),
%% @NOTE: msquic returns not_found when it is unset.
{error, Reason} = quicer:getopt(Conn, close_reason_phrase),
?assert(Reason == not_found orelse Reason == closed),
SPid ! done,
ensure_server_exit_normal(Ref)
after 5000 ->
Expand Down Expand Up @@ -1370,7 +1371,8 @@ tc_setopt(Config) ->

{error, not_supported} = quicer:setopt(Conn, ideal_processor, 1),
{error, not_supported} = quicer:setopt(Conn, max_stream_ids, [1, 2, 3, 4]),
ok = quicer:setopt(Conn, close_reason_phrase, "You are not welcome!"),
ok = quicer:setopt(Conn, close_reason_phrase, "You are not welcomed!"),
{ok, <<"You are not welcomed!">>} = quicer:getopt(Conn, close_reason_phrase),
ok = quicer:setopt(Conn, stream_scheduling_scheme, 1),
{ok, 1} = quicer:getopt(Conn, stream_scheduling_scheme),
%% get-only
Expand Down

0 comments on commit 9f53b72

Please sign in to comment.