diff --git a/c_src/quicer_config.c b/c_src/quicer_config.c index 33df9714..565c73e8 100644 --- a/c_src/quicer_config.c +++ b/c_src/quicer_config.c @@ -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) { diff --git a/test/quicer_SUITE.erl b/test/quicer_SUITE.erl index 0cc5af7a..a11e45c9 100644 --- a/test/quicer_SUITE.erl +++ b/test/quicer_SUITE.erl @@ -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 -> @@ -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