Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed Oct 10, 2023
1 parent 6d0b633 commit b6886f0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
5 changes: 3 additions & 2 deletions c_src/quicer_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,9 @@ getopt3(ErlNifEnv *env,
if (IS_SAME_TERM(ATOM_QUIC_GLOBAL, ctx))
{
pthread_mutex_lock(&MsQuicLock);
// Get global option without using any ctx
// We are risking using a closed lib
// In a env that while there is no allocated NIF resources (reg, conf,
// listener, conn, stream), VM may unload the module causes unloading DSO
// in parallel.
if (MsQuic)
{
res = get_global_opt(env, NULL, eopt);
Expand Down
10 changes: 6 additions & 4 deletions c_src/quicer_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,16 @@ resource_listener_down_callback(__unused_parm__ ErlNifEnv *env,
if (!l_ctx->is_closed && !l_ctx->is_stopped && l_ctx->Listener)
{
l_ctx->is_stopped = TRUE;
/*
// We only stop here, but not close it, because possible subsequent
// scenarios:
// a. Some pid could still start the stopped listener with nif
// handle
// handle.
// b. Some pid could still close the stopped listener with nif
// handle
// c. We close it in resource_listener_dealloc_callback anyway.
// handle.
// c. We close it in resource_listener_dealloc_callback anyway when
// Listener term get GC.
*/
MsQuic->ListenerStop(l_ctx->Listener);
}
enif_mutex_unlock(l_ctx->lock);
Expand Down Expand Up @@ -903,7 +906,6 @@ resource_stream_dealloc_callback(__unused_parm__ ErlNifEnv *env, void *obj)
assert(s_ctx->is_closed == TRUE);
if (s_ctx->Stream)
{

MsQuic->StreamClose(s_ctx->Stream);
}

Expand Down
15 changes: 15 additions & 0 deletions c_src/quicer_vsn.h.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*--------------------------------------------------------------------
Copyright (c) 2023 EMQ Technologies Co., Ltd. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-------------------------------------------------------------------*/
#ifndef __QUICER_VSN_H_
#define __QUICER_VSN_H_

Expand Down
15 changes: 15 additions & 0 deletions include/quicer_vsn.hrl.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2023 EMQ Technologies Co., Ltd. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%--------------------------------------------------------------------
-ifndef(QUICER_VSN_HRL).
-define(QUICER_VSN_HRL, true).
-define(QUICER_ABI_VERSION, @QUICER_ABI_VERSION@).
Expand Down
2 changes: 1 addition & 1 deletion test/quicer_snb_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1023,13 +1023,13 @@ tc_conn_no_gc(Config) ->
{ok, Conn} = quicer:connect("localhost", Port, [{idle_timeout_ms, 1000},
{verify, none},
{alpn, ["sample"]}], 5000),
{ok, CRid} = quicer:get_conn_rid(Conn),
_Child = spawn_link(fun() ->
{ok, Stm} = quicer:start_stream(Conn, [{active, false}]),
{ok, 4} = quicer:async_send(Stm, <<"ping">>),
{ok, <<"ping">>} = quicer:recv(Stm, 4),
quicer:shutdown_connection(Conn, 0, 0)
end),
{ok, CRid} = quicer:get_conn_rid(Conn),
%% Server Process
{ok, #{resource_id := SRid}}
= ?block_until(#{ ?snk_kind := debug
Expand Down

0 comments on commit b6886f0

Please sign in to comment.