Skip to content

Commit

Permalink
fix(listener): mark listener stopped in resource down callback
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed Sep 4, 2023
1 parent a745039 commit 24065b0
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions c_src/quicer_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,14 +765,28 @@ resource_listener_down_callback(__unused_parm__ ErlNifEnv *env,
{
QuicerListenerCTX *l_ctx = (QuicerListenerCTX *)ctx;
TP_CB_3(start, (uintptr_t)l_ctx->Listener, 0);
if (l_ctx->Listener)
{
MsQuic->ListenerStop(l_ctx->Listener);
}

BOOLEAN to_stop = FALSE;
enif_mutex_lock(l_ctx->lock);
if (!l_ctx->is_closed && !l_ctx->is_stopped && l_ctx->Listener)
{
to_stop = TRUE;
l_ctx->is_stopped = TRUE;
}
enif_mutex_unlock(l_ctx->lock);
if (to_stop)
{
// We only stop here, but not close it, because we want to
// close it in resource_listener_dealloc_callback
// Or some pid could still start the stopped listener with nif handle
MsQuic->ListenerStop(l_ctx->Listener);
}
TP_CB_3(end, (uintptr_t)l_ctx->Listener, 0);
}


/*
** Listener NIF handle, end of world...
*/
void
resource_listener_dealloc_callback(__unused_parm__ ErlNifEnv *env, void *obj)
{
Expand Down

0 comments on commit 24065b0

Please sign in to comment.