Skip to content

Commit

Permalink
Merge pull request #286 from qzhuyan/dev/william/lb-msquic2.3.5
Browse files Browse the repository at this point in the history
 LB feature in msquic2.3.5
  • Loading branch information
qzhuyan authored May 22, 2024
2 parents c56bdf2 + 2aca923 commit 28c72d3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
21 changes: 17 additions & 4 deletions c_src/quicer_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1148,14 +1148,14 @@ on_unload(__unused_parm__ ErlNifEnv *env, __unused_parm__ void *priv_data)
}

static ERL_NIF_TERM
openLib(ErlNifEnv *env, __unused_parm__ int argc, const ERL_NIF_TERM argv[])
openLib(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
assert(1 == argc);
CXPLAT_FRE_ASSERT(argc == 1);
TP_NIF_3(enter, 0, 1);
QUIC_STATUS status = QUIC_STATUS_SUCCESS;
ERL_NIF_TERM res = ATOM_FALSE;
ERL_NIF_TERM lttngLib = argv[0];
char lttngPath[PATH_MAX] = { 0 };
unsigned int lb_mode = 0;

pthread_mutex_lock(&MsQuicLock);
if (MsQuic)
Expand All @@ -1180,7 +1180,20 @@ openLib(ErlNifEnv *env, __unused_parm__ int argc, const ERL_NIF_TERM argv[])

res = SUCCESS(ATOM_TRUE);

if (enif_get_string(env, lttngLib, lttngPath, PATH_MAX, ERL_NIF_LATIN1))
ERL_NIF_TERM eterm = ATOM_UNDEFINED;

if (enif_get_map_value(
env, argv[0], ATOM_QUIC_PARAM_GLOBAL_LOAD_BALACING_MODE, &eterm)
&& enif_get_uint(env, eterm, &lb_mode))
{
MsQuic->SetParam(NULL,
QUIC_PARAM_GLOBAL_LOAD_BALACING_MODE,
sizeof(uint16_t),
(uint16_t *)&lb_mode);
}

if (enif_get_map_value(env, argv[0], ATOM_TRACE, &eterm)
&& enif_get_string(env, eterm, lttngPath, PATH_MAX, ERL_NIF_LATIN1))
{
// loading lttng lib is optional, ok to fail
if (dlopen(lttngPath, (unsigned)RTLD_NOW | (unsigned)RTLD_GLOBAL))
Expand Down
2 changes: 1 addition & 1 deletion src/quicer.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
stdlib
]},
{mod, {quicer_app, []}},
{env, []},
{env, [{lb_mode, 0}]},
{modules, [
quicer,
quicer_app,
Expand Down
5 changes: 4 additions & 1 deletion src/quicer_nif.erl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ open_lib() ->
{error, _} ->
priv_dir()
end,
open_lib(LibFile).
open_lib(#{
load_balacing_mode => application:get_env(quicer, lb_mode, 0),
trace => LibFile
}).

open_lib(_LttngLib) ->
erlang:nif_error(nif_library_not_loaded).
Expand Down

0 comments on commit 28c72d3

Please sign in to comment.