Skip to content

Commit

Permalink
Merge pull request #225 from qzhuyan/dev/william/nif-module-reload
Browse files Browse the repository at this point in the history
API synchronization
  • Loading branch information
qzhuyan committed Oct 23, 2023
2 parents f6c710e + 97979b5 commit 9cfccfa
Show file tree
Hide file tree
Showing 12 changed files with 419 additions and 232 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ endif()
if (DEFINED ENV{QUIC_LOGGING_TYPE})
set(QUIC_ENABLE_LOGGING "ON")
set(QUIC_LOGGING_TYPE $ENV{QUIC_LOGGING_TYPE})
if (${QUIC_LOGGING_TYPE} STREQUAL "stdout")
add_compile_options(-DQUICER_LOGGING_STDOUT)
endif()
endif()

if (DEFINED ENV{QUICER_USE_LTTNG} AND DEFINED ENV{QUICER_USE_SNK})
Expand Down
38 changes: 34 additions & 4 deletions c_src/quicer_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,22 +781,38 @@ getopt3(ErlNifEnv *env,
}
else if (enif_get_resource(env, ctx, ctx_stream_t, &q_ctx))
{
if (!get_stream_handle(q_ctx))
{
goto Exit;
}
res = get_stream_opt(env, (QuicerStreamCTX *)q_ctx, eopt, elevel);
put_stream_handle(q_ctx);
}
else if (enif_get_resource(env, ctx, ctx_connection_t, &q_ctx))
{
if (!get_conn_handle(q_ctx))
{
goto Exit;
}
res = get_connection_opt(env, (QuicerConnCTX *)q_ctx, eopt, elevel);
put_conn_handle(q_ctx);
}
else if (enif_get_resource(env, ctx, ctx_listener_t, &q_ctx))
{
if (!get_listener_handle(q_ctx))
{
goto Exit;
}
res = get_listener_opt(env, (QuicerListenerCTX *)q_ctx, eopt, elevel);
put_listener_handle(q_ctx);
}
else
{ //@todo support GLOBAL, REGISTRATION and CONFIGURATION
return ERROR_TUPLE_2(ATOM_BADARG);
}

return res;
Exit:
return ERROR_TUPLE_2(ATOM_CLOSED);
}

ERL_NIF_TERM
Expand Down Expand Up @@ -863,25 +879,42 @@ setopt4(ErlNifEnv *env, __unused_parm__ int argc, const ERL_NIF_TERM argv[])
}
else if (enif_get_resource(env, ctx, ctx_stream_t, &q_ctx))
{
if (!get_stream_handle(q_ctx))
{
goto Exit;
}
res = set_stream_opt(
env, (QuicerStreamCTX *)q_ctx, eopt, evalue, elevel);
put_stream_handle(q_ctx);
}
else if (enif_get_resource(env, ctx, ctx_connection_t, &q_ctx))
{
if (!get_conn_handle(q_ctx))
{
goto Exit;
}
res = set_connection_opt(
env, (QuicerConnCTX *)q_ctx, eopt, evalue, elevel);
put_conn_handle(q_ctx);
}
else if (enif_get_resource(env, ctx, ctx_listener_t, &q_ctx))
{
if (!get_listener_handle(q_ctx))
{
goto Exit;
}
res = set_listener_opt(
env, (QuicerListenerCTX *)q_ctx, eopt, evalue, elevel);
put_listener_handle(q_ctx);
}
else
{ //@todo support GLOBAL, REGISTRATION and CONFIGURATION
return ERROR_TUPLE_2(ATOM_BADARG);
}

return res;
Exit:
return ERROR_TUPLE_2(ATOM_CLOSED);
}

bool
Expand Down Expand Up @@ -1884,14 +1917,11 @@ get_listener_opt(ErlNifEnv *env,
return ERROR_TUPLE_2(ATOM_BADARG);
}

enif_mutex_lock(l_ctx->lock);
if (l_ctx->is_closed)
{
enif_mutex_unlock(l_ctx->lock);
return ERROR_TUPLE_2(ATOM_CLOSED);
}
enif_keep_resource(l_ctx);
enif_mutex_unlock(l_ctx->lock);

if (!IS_SAME_TERM(ATOM_FALSE, elevel))
{
Expand Down
Loading

0 comments on commit 9cfccfa

Please sign in to comment.