Skip to content

Commit

Permalink
test(helper): quicer_nif:copy_stream_handle/1
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed Oct 30, 2024
1 parent 895252a commit 32ef743
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions c_src/quicer_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,18 @@ cleanup_owner_signals(QuicerStreamCTX *s_ctx)
OwnerSignalQueueDestroy(s_ctx->sig_queue);
s_ctx->sig_queue = NULL;
}

ERL_NIF_TERM
copy_stream_handle(ErlNifEnv *env,
__unused_parm__ int argc,
const ERL_NIF_TERM argv[])
{
QuicerStreamCTX *ctx = NULL;
if (!enif_get_resource(env, argv[0], ctx_stream_t, (void **)&ctx))
{
return enif_make_badarg(env);
}
assert(ctx != NULL);
enif_make_copy(ctx->env, ctx->eHandle);
return ATOM_OK;
}
3 changes: 3 additions & 0 deletions c_src/quicer_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,7 @@ void cache_stream_id(QuicerStreamCTX *s_ctx);

void cleanup_owner_signals(QuicerStreamCTX *s_ctx);

ERL_NIF_TERM
copy_stream_handle(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);

#endif // __QUICER_CTX_H_
1 change: 1 addition & 0 deletions c_src/quicer_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,7 @@ static ErlNifFunc nif_funcs[] = {
{ "get_conn_owner", 1, get_conn_owner1, 0},
{ "get_stream_owner", 1, get_stream_owner1, 0},
{ "get_listener_owner", 1, get_listener_owner1, 0},
{ "copy_stream_handle", 1, copy_stream_handle, 0},
/* for testing */
{ "mock_buffer_sig", 3, mock_buffer_sig, 0},
#ifdef QUICER_USE_SNK
Expand Down
5 changes: 5 additions & 0 deletions src/quicer_nif.erl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
get_conn_owner/1,
get_stream_owner/1,
get_listener_owner/1,
copy_stream_handle/1,
mock_buffer_sig/3,
set_snab_kc_pid/1,
get_snab_kc_pid/0
Expand Down Expand Up @@ -385,6 +386,10 @@ get_connections() ->
get_connections(_RegHandle) ->
erlang:nif_error(nif_library_not_loaded).

-spec copy_stream_handle(stream_handle()) -> {ok, stream_handle()} | {error, badarg}.
copy_stream_handle(_H) ->
erlang:nif_error(nif_library_not_loaded).

%% @doc enable signal buffering, used in stream handoff.
%% * not exposed API.
-spec enable_sig_buffer(stream_handle()) -> ok.
Expand Down

0 comments on commit 32ef743

Please sign in to comment.