diff --git a/c_src/quicer_ctx.c b/c_src/quicer_ctx.c index 43f85280..45e7adf6 100644 --- a/c_src/quicer_ctx.c +++ b/c_src/quicer_ctx.c @@ -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; +} diff --git a/c_src/quicer_ctx.h b/c_src/quicer_ctx.h index 9482ed93..9068566d 100644 --- a/c_src/quicer_ctx.h +++ b/c_src/quicer_ctx.h @@ -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_ diff --git a/c_src/quicer_nif.c b/c_src/quicer_nif.c index 4cbd8b93..5dca270d 100644 --- a/c_src/quicer_nif.c +++ b/c_src/quicer_nif.c @@ -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 diff --git a/src/quicer_nif.erl b/src/quicer_nif.erl index 16fa7934..6d35e00a 100644 --- a/src/quicer_nif.erl +++ b/src/quicer_nif.erl @@ -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 @@ -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.