diff --git a/c_src/quicer_config.c b/c_src/quicer_config.c index 31a35c1c..f970873f 100644 --- a/c_src/quicer_config.c +++ b/c_src/quicer_config.c @@ -20,7 +20,7 @@ limitations under the License. #include "quicer_tls.h" #include -extern BOOLEAN isRegistered; +extern QuicerRegistrationCTX *G_r_ctx; static ERL_NIF_TERM get_stream_opt(ErlNifEnv *env, QuicerStreamCTX *s_ctx, @@ -217,7 +217,7 @@ ServerLoadConfiguration(ErlNifEnv *env, { QUIC_SETTINGS Settings = { 0 }; - if (!isRegistered && (Registration == GRegistration)) + if (!G_r_ctx) { return ATOM_REG_FAILED; } @@ -273,7 +273,7 @@ ClientLoadConfiguration(ErlNifEnv *env, QUIC_SETTINGS Settings = { 0 }; ERL_NIF_TERM ret = ATOM_OK; - if (!isRegistered && (Registration == GRegistration)) + if (!G_r_ctx) { return ATOM_REG_FAILED; } diff --git a/c_src/quicer_connection.c b/c_src/quicer_connection.c index 4bccc9e4..a3956397 100644 --- a/c_src/quicer_connection.c +++ b/c_src/quicer_connection.c @@ -23,6 +23,8 @@ limitations under the License. #include #include +extern QuicerRegistrationCTX *G_r_ctx; + #ifdef DEBUG extern inline void EncodeHexBuffer(uint8_t *Buffer, uint8_t BufferLen, char *HexString); @@ -505,7 +507,14 @@ open_connectionX(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) if (argc == 0) { - registration = GRegistration; + if (G_r_ctx) + { + registration = G_r_ctx->Registration; + } + else + { + return ERROR_TUPLE_2(ATOM_QUIC_REGISTRATION); + } r_ctx = NULL; } else @@ -522,7 +531,14 @@ open_connectionX(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) } else { - registration = GRegistration; + if (G_r_ctx) + { + registration = G_r_ctx->Registration; + } + else + { + return ERROR_TUPLE_2(ATOM_QUIC_REGISTRATION); + } } } @@ -619,7 +635,14 @@ async_connect3(ErlNifEnv *env, } else { - Registration = GRegistration; + if (G_r_ctx) + { + Registration = G_r_ctx->Registration; + } + else + { + return ERROR_TUPLE_2(ATOM_REG_FAILED); + } } } else @@ -649,7 +672,14 @@ async_connect3(ErlNifEnv *env, { // quic_registration is not set, use global registration // msquic should reject if global registration is NULL (closed) - Registration = GRegistration; + if (G_r_ctx && G_r_ctx->Registration) + { + Registration = G_r_ctx->Registration; + } + else + { + Registration = NULL; + } } if ((c_ctx->owner = AcceptorAlloc()) == NULL) diff --git a/c_src/quicer_ctx.c b/c_src/quicer_ctx.c index b5c376c6..910d25a4 100644 --- a/c_src/quicer_ctx.c +++ b/c_src/quicer_ctx.c @@ -17,6 +17,7 @@ limitations under the License. #include "quicer_ctx.h" // alloc/dealloc ctx should be done in the callbacks. +extern QuicerRegistrationCTX *G_r_ctx; QuicerRegistrationCTX * init_r_ctx() @@ -81,7 +82,7 @@ deinit_l_ctx(QuicerListenerCTX *l_ctx) { destroy_config_ctx(l_ctx->config_resource); } - if (l_ctx->r_ctx && l_ctx->r_ctx->Registration != GRegistration) + if (l_ctx->r_ctx && l_ctx->r_ctx != G_r_ctx) { enif_release_resource(l_ctx->r_ctx); } diff --git a/c_src/quicer_eterms.h b/c_src/quicer_eterms.h index c0b6d2fc..7a5d6e1d 100644 --- a/c_src/quicer_eterms.h +++ b/c_src/quicer_eterms.h @@ -35,6 +35,7 @@ extern ERL_NIF_TERM ATOM_BAD_MON; extern ERL_NIF_TERM ATOM_LISTENER_OPEN_ERROR; extern ERL_NIF_TERM ATOM_LISTENER_START_ERROR; extern ERL_NIF_TERM ATOM_BADARG; +extern ERL_NIF_TERM ATOM_LIB_UNINITIALIZED; extern ERL_NIF_TERM ATOM_CONN_OPEN_ERROR; extern ERL_NIF_TERM ATOM_CONN_START_ERROR; extern ERL_NIF_TERM ATOM_STREAM_OPEN_ERROR; diff --git a/c_src/quicer_listener.c b/c_src/quicer_listener.c index f8fdfe78..f590f165 100644 --- a/c_src/quicer_listener.c +++ b/c_src/quicer_listener.c @@ -22,6 +22,8 @@ limitations under the License. #include #include +extern QuicerRegistrationCTX *G_r_ctx; + BOOLEAN parse_registration(ErlNifEnv *env, ERL_NIF_TERM options, QuicerRegistrationCTX **r_ctx); @@ -274,6 +276,7 @@ listen2(ErlNifEnv *env, __unused_parm__ int argc, const ERL_NIF_TERM argv[]) if (!parse_cacertfile_option(env, options, &cacertfile)) { // TLS opt error not file content error + free(cacertfile); return ERROR_TUPLE_2(ATOM_CACERTFILE); } @@ -282,6 +285,7 @@ listen2(ErlNifEnv *env, __unused_parm__ int argc, const ERL_NIF_TERM argv[]) if (!l_ctx) { + free(cacertfile); return ERROR_TUPLE_2(ATOM_ERROR_NOT_ENOUGH_MEMORY); } @@ -325,7 +329,15 @@ listen2(ErlNifEnv *env, __unused_parm__ int argc, const ERL_NIF_TERM argv[]) { // quic_registration is not set, use global registration // msquic should reject if global registration is NULL (closed) - Registration = GRegistration; + if (G_r_ctx) + { + Registration = G_r_ctx->Registration; + } + else + { + ret = ERROR_TUPLE_2(ATOM_QUIC_REGISTRATION); + goto exit; + } } // Now load server config @@ -400,6 +412,7 @@ listen2(ErlNifEnv *env, __unused_parm__ int argc, const ERL_NIF_TERM argv[]) return OK_TUPLE_2(listenHandle); exit: // errors.. + free(cacertfile); free_certificate(&CredConfig); destroy_l_ctx(l_ctx); return ret; diff --git a/c_src/quicer_nif.c b/c_src/quicer_nif.c index 11f3a2ed..bb72801c 100644 --- a/c_src/quicer_nif.c +++ b/c_src/quicer_nif.c @@ -33,6 +33,9 @@ static ERL_NIF_TERM stream_controlling_process(ErlNifEnv *env, const ErlNifPid *caller, const ERL_NIF_TERM *pid); +static ERL_NIF_TERM +closeLib(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); + /* ** atoms in use, initialized while load nif */ @@ -54,6 +57,7 @@ ERL_NIF_TERM ATOM_BAD_MON; ERL_NIF_TERM ATOM_LISTENER_OPEN_ERROR; ERL_NIF_TERM ATOM_LISTENER_START_ERROR; ERL_NIF_TERM ATOM_BADARG; +ERL_NIF_TERM ATOM_LIB_UNINITIALIZED; ERL_NIF_TERM ATOM_CONN_OPEN_ERROR; ERL_NIF_TERM ATOM_CONN_START_ERROR; ERL_NIF_TERM ATOM_STREAM_OPEN_ERROR; @@ -430,6 +434,7 @@ ERL_NIF_TERM ATOM_QUIC_DATAGRAM_SEND_CANCELED; ATOM(ATOM_LISTENER_OPEN_ERROR, listener_open_error); \ ATOM(ATOM_LISTENER_START_ERROR, listener_start_error); \ ATOM(ATOM_BADARG, badarg); \ + ATOM(ATOM_LIB_UNINITIALIZED, lib_uninitialized); \ ATOM(ATOM_CONN_OPEN_ERROR, conn_open_error); \ ATOM(ATOM_CONN_START_ERROR, conn_start_error); \ ATOM(ATOM_STREAM_OPEN_ERROR, stm_open_error); \ @@ -768,12 +773,12 @@ ERL_NIF_TERM ATOM_QUIC_DATAGRAM_SEND_CANCELED; ATOM(ATOM_QUIC_DATAGRAM_SEND_CANCELED, dgram_send_canceled); \ ATOM(ATOM_UNDEFINED, undefined); -HQUIC GRegistration = NULL; -const QUIC_API_TABLE *MsQuic = NULL; +extern QuicerRegistrationCTX *G_r_ctx; +extern pthread_mutex_t GRegLock; -// @todo, these flags are not threads safe, wrap it in a context -BOOLEAN isRegistered = false; -BOOLEAN isLibOpened = false; +const QUIC_API_TABLE *MsQuic = NULL; +// Mutex for MsQuic +pthread_mutex_t MsQuicLock = PTHREAD_MUTEX_INITIALIZER; ErlNifResourceType *ctx_reg_t = NULL; ErlNifResourceType *ctx_listener_t = NULL; @@ -935,7 +940,7 @@ resource_config_dealloc_callback(__unused_parm__ ErlNifEnv *env, TP_CB_3(start, (uintptr_t)obj, 0); QuicerConfigCTX *config_ctx = (QuicerConfigCTX *)obj; // Check if Registration is closed or not - if (GRegistration && config_ctx->Configuration) + if (G_r_ctx && config_ctx->Configuration) { MsQuic->ConfigurationClose(config_ctx->Configuration); } @@ -949,7 +954,7 @@ resource_reg_dealloc_callback(__unused_parm__ ErlNifEnv *env, void *obj) TP_CB_3(start, (uintptr_t)obj, 0); QuicerRegistrationCTX *reg_ctx = (QuicerRegistrationCTX *)obj; deinit_r_ctx(reg_ctx); - if (reg_ctx->Registration) + if (MsQuic && reg_ctx->Registration) { MsQuic->RegistrationClose(reg_ctx->Registration); } @@ -1048,18 +1053,7 @@ on_upgrade(ErlNifEnv *env, static void on_unload(__unused_parm__ ErlNifEnv *env, __unused_parm__ void *priv_data) { - // @TODO We want registration context and APIs for it - if (isRegistered) - { - MsQuic->RegistrationClose(GRegistration); - isRegistered = FALSE; - } - - if (isLibOpened) - { - MsQuicClose(MsQuic); - isLibOpened = FALSE; - } + closeLib(env, 0, NULL); } static ERL_NIF_TERM @@ -1072,40 +1066,41 @@ openLib(ErlNifEnv *env, __unused_parm__ int argc, const ERL_NIF_TERM argv[]) ERL_NIF_TERM lttngLib = argv[0]; char lttngPath[PATH_MAX] = { 0 }; - if (isLibOpened) + pthread_mutex_lock(&MsQuicLock); + if (MsQuic) { + // already opened TP_NIF_3(skip, 0, 2); - return SUCCESS(res); + res = SUCCESS(res); + goto exit; } - // @todo external call for static link - CxPlatSystemLoad(); - MsQuicLibraryLoad(); - // // Open a handle to the library and get the API function table. // if (QUIC_FAILED(status = MsQuicOpen2(&MsQuic))) { - isLibOpened = false; - return ERROR_TUPLE_3(ATOM_OPEN_FAILED, ATOM_STATUS(status)); + MsQuic = NULL; + res = ERROR_TUPLE_3(ATOM_OPEN_FAILED, ATOM_STATUS(status)); + goto exit; } - isLibOpened = true; TP_NIF_3(success, 0, 2); - res = ATOM_TRUE; + res = SUCCESS(ATOM_TRUE); if (enif_get_string(env, lttngLib, lttngPath, PATH_MAX, ERL_NIF_LATIN1)) { // loading lttng lib is optional, ok to fail if (dlopen(lttngPath, (unsigned)RTLD_NOW | (unsigned)RTLD_GLOBAL)) { - res = ATOM_DEBUG; + res = SUCCESS(ATOM_DEBUG); } } - return SUCCESS(res); +exit: + pthread_mutex_unlock(&MsQuicLock); + return res; } static ERL_NIF_TERM @@ -1113,83 +1108,30 @@ closeLib(__unused_parm__ ErlNifEnv *env, __unused_parm__ int argc, __unused_parm__ const ERL_NIF_TERM argv[]) { - if (isLibOpened && MsQuic) + pthread_mutex_lock(&MsQuicLock); + if (MsQuic) { - // @todo ensure registration is closed first - // - TP_NIF_3(do_close, 0, isLibOpened); - MsQuicClose(MsQuic); - isLibOpened = false; - } - - return ATOM_OK; -} - -/* -** For global registration only -*/ -static ERL_NIF_TERM -registration(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) -{ - QUIC_STATUS status = QUIC_STATUS_SUCCESS; - ERL_NIF_TERM profile = argv[0]; + TP_NIF_3(do_close, MsQuic, 0); - if (isRegistered || !isLibOpened) - { - return ERROR_TUPLE_2(ATOM_BADARG); - } - - if (argc == 1) - { - if (IS_SAME_TERM(profile, ATOM_QUIC_EXECUTION_PROFILE_LOW_LATENCY)) - { - GRegConfig.ExecutionProfile = QUIC_EXECUTION_PROFILE_LOW_LATENCY; - } - else if (IS_SAME_TERM(profile, - ATOM_QUIC_EXECUTION_PROFILE_TYPE_MAX_THROUGHPUT)) + pthread_mutex_lock(&GRegLock); + // end of the world + if (G_r_ctx && !G_r_ctx->is_released) { - GRegConfig.ExecutionProfile - = QUIC_EXECUTION_PROFILE_TYPE_MAX_THROUGHPUT; + // Make MsQuic debug check pass: + // Zero Registration when closing MsQuic + MsQuic->RegistrationClose(G_r_ctx->Registration); + G_r_ctx->Registration = NULL; + G_r_ctx->is_released = TRUE; + destroy_r_ctx(G_r_ctx); + G_r_ctx = NULL; } - else if (IS_SAME_TERM(profile, - ATOM_QUIC_EXECUTION_PROFILE_TYPE_SCAVENGER)) - { - GRegConfig.ExecutionProfile = QUIC_EXECUTION_PROFILE_TYPE_SCAVENGER; - } - else if (IS_SAME_TERM(profile, - ATOM_QUIC_EXECUTION_PROFILE_TYPE_REAL_TIME)) - { - GRegConfig.ExecutionProfile = QUIC_EXECUTION_PROFILE_TYPE_REAL_TIME; - } - else - { - return ERROR_TUPLE_2(ATOM_BADARG); - } - } - // Open global registration - if (QUIC_FAILED(status - = MsQuic->RegistrationOpen(&GRegConfig, &GRegistration))) - { - isRegistered = false; - TP_NIF_3(fail, 0, status); - return ERROR_TUPLE_3(ATOM_REG_FAILED, ETERM_INT(status)); - } - TP_NIF_3(success, 0, status); - isRegistered = true; - return ATOM_OK; -} + pthread_mutex_unlock(&GRegLock); -static ERL_NIF_TERM -deregistration(__unused_parm__ ErlNifEnv *env, - __unused_parm__ int argc, - __unused_parm__ const ERL_NIF_TERM argv[]) -{ - if (isRegistered && GRegistration) - { - MsQuic->RegistrationClose(GRegistration); - GRegistration = NULL; - isRegistered = false; + MsQuicClose(MsQuic); + MsQuic = NULL; } + + pthread_mutex_unlock(&MsQuicLock); return ATOM_OK; } diff --git a/c_src/quicer_nif.h b/c_src/quicer_nif.h index cf2b1686..b7ed558f 100644 --- a/c_src/quicer_nif.h +++ b/c_src/quicer_nif.h @@ -41,7 +41,6 @@ limitations under the License. // Global registration // @todo avoid use globals -extern HQUIC GRegistration; extern const QUIC_API_TABLE *MsQuic; extern QUIC_REGISTRATION_CONFIG GRegConfig; diff --git a/c_src/quicer_reg.c b/c_src/quicer_reg.c index 20b03ec8..91bdf52f 100644 --- a/c_src/quicer_reg.c +++ b/c_src/quicer_reg.c @@ -16,42 +16,37 @@ limitations under the License. #include "quicer_reg.h" #include "quicer_nif.h" +static BOOLEAN parse_reg_conf(ERL_NIF_TERM eprofile, + QUIC_REGISTRATION_CONFIG *RegConfig); + +QuicerRegistrationCTX *G_r_ctx = NULL; +pthread_mutex_t GRegLock = PTHREAD_MUTEX_INITIALIZER; + +/* +** For global registration only +*/ ERL_NIF_TERM -new_registration2(ErlNifEnv *env, - __unused_parm__ int argc, - const ERL_NIF_TERM argv[]) +registration(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { - QUIC_STATUS status = QUIC_STATUS_SUCCESS; - ERL_NIF_TERM ename = argv[0]; + ERL_NIF_TERM eprofile = ATOM_UNDEFINED; QUIC_REGISTRATION_CONFIG RegConfig - = { NULL, QUIC_EXECUTION_PROFILE_LOW_LATENCY }; + = { "global", QUIC_EXECUTION_PROFILE_LOW_LATENCY }; + QUIC_STATUS status; + ERL_NIF_TERM res = ATOM_OK; - TP_NIF_3(start, 0, status); - if (argc == 2) + if (!MsQuic || G_r_ctx) { - ERL_NIF_TERM eprofile = argv[1]; - if (IS_SAME_TERM(eprofile, ATOM_QUIC_EXECUTION_PROFILE_LOW_LATENCY)) - { - RegConfig.ExecutionProfile = QUIC_EXECUTION_PROFILE_LOW_LATENCY; - } - else if (IS_SAME_TERM(eprofile, - ATOM_QUIC_EXECUTION_PROFILE_TYPE_MAX_THROUGHPUT)) - { - RegConfig.ExecutionProfile - = QUIC_EXECUTION_PROFILE_TYPE_MAX_THROUGHPUT; - } - else if (IS_SAME_TERM(eprofile, - ATOM_QUIC_EXECUTION_PROFILE_TYPE_SCAVENGER)) - { - RegConfig.ExecutionProfile = QUIC_EXECUTION_PROFILE_TYPE_SCAVENGER; - } - else if (IS_SAME_TERM(eprofile, - ATOM_QUIC_EXECUTION_PROFILE_TYPE_REAL_TIME)) - { - RegConfig.ExecutionProfile = QUIC_EXECUTION_PROFILE_TYPE_REAL_TIME; - } - else + return ERROR_TUPLE_2(ATOM_BADARG); + } + + pthread_mutex_lock(&GRegLock); + + if (argc == 1) + { + eprofile = argv[0]; + if (!parse_reg_conf(eprofile, &RegConfig)) { + pthread_mutex_unlock(&GRegLock); return ERROR_TUPLE_2(ATOM_BADARG); } } @@ -59,29 +54,99 @@ new_registration2(ErlNifEnv *env, QuicerRegistrationCTX *r_ctx = init_r_ctx(); if (!r_ctx) { - ERROR_TUPLE_2(ATOM_ERROR_NOT_ENOUGH_MEMORY); + pthread_mutex_unlock(&GRegLock); + return ERROR_TUPLE_2(ATOM_ERROR_NOT_ENOUGH_MEMORY); } - if (0 >= enif_get_string( - env, ename, r_ctx->name, UINT8_MAX + 1, ERL_NIF_LATIN1)) + if (QUIC_FAILED( + status = MsQuic->RegistrationOpen(&RegConfig, &r_ctx->Registration))) { - deinit_r_ctx(r_ctx); - destroy_r_ctx(r_ctx); - ERROR_TUPLE_2(ATOM_BADARG); + res = ERROR_TUPLE_2(ATOM_STATUS(status)); + goto exit; + } + + G_r_ctx = r_ctx; + pthread_mutex_unlock(&GRegLock); + + // nif owns the global registration + // thus not return to the erlang side + return ATOM_OK; + +exit: + destroy_r_ctx(r_ctx); + pthread_mutex_unlock(&GRegLock); + return res; +} + +/* +** For global registration only +*/ +ERL_NIF_TERM +deregistration(__unused_parm__ ErlNifEnv *env, + __unused_parm__ int argc, + __unused_parm__ const ERL_NIF_TERM argv[]) +{ + int error_code = 0; + if (!MsQuic) + { + return ERROR_TUPLE_2(ATOM_BADARG); } - // Open Registration + pthread_mutex_lock(&GRegLock); + if (G_r_ctx && !G_r_ctx->is_released) + { + MsQuic->RegistrationShutdown(G_r_ctx->Registration, FALSE, error_code); + destroy_r_ctx(G_r_ctx); + G_r_ctx = NULL; + } + pthread_mutex_unlock(&GRegLock); + return ATOM_OK; +} + +ERL_NIF_TERM +new_registration2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) +{ + + ERL_NIF_TERM ename = argv[0]; + ERL_NIF_TERM eprofile = argv[1]; + QUIC_REGISTRATION_CONFIG RegConfig + = { NULL, QUIC_EXECUTION_PROFILE_LOW_LATENCY }; + + QUIC_STATUS status; + ERL_NIF_TERM res = ATOM_OK; + + if (!parse_reg_conf(eprofile, &RegConfig)) + { + return ERROR_TUPLE_2(ATOM_BADARG); + } + + QuicerRegistrationCTX *r_ctx = init_r_ctx(); + if (!r_ctx) + { + return ERROR_TUPLE_2(ATOM_ERROR_NOT_ENOUGH_MEMORY); + } + + if (argc == 2 + && 0 >= enif_get_string( + env, ename, r_ctx->name, UINT8_MAX + 1, ERL_NIF_LATIN1)) + { + res = ERROR_TUPLE_2(ATOM_BADARG); + goto exit; + } + + RegConfig.AppName = r_ctx->name; if (QUIC_FAILED( status = MsQuic->RegistrationOpen(&RegConfig, &r_ctx->Registration))) { - // unlikely - TP_NIF_3(fail, 0, status); - deinit_r_ctx(r_ctx); - destroy_r_ctx(r_ctx); - return ERROR_TUPLE_2(ATOM_STATUS(status)); + res = ERROR_TUPLE_2(ATOM_STATUS(status)); + goto exit; } - TP_NIF_3(success, 0, status); + return SUCCESS(enif_make_resource(env, r_ctx)); + +exit: + destroy_r_ctx(r_ctx); + return res; } ERL_NIF_TERM @@ -142,3 +207,30 @@ get_registration_name1(ErlNifEnv *env, return SUCCESS(enif_make_string(env, r_ctx->name, ERL_NIF_LATIN1)); } + +BOOLEAN +parse_reg_conf(ERL_NIF_TERM eprofile, QUIC_REGISTRATION_CONFIG *RegConfig) +{ + if (IS_SAME_TERM(eprofile, ATOM_QUIC_EXECUTION_PROFILE_LOW_LATENCY)) + { + RegConfig->ExecutionProfile = QUIC_EXECUTION_PROFILE_LOW_LATENCY; + } + else if (IS_SAME_TERM(eprofile, + ATOM_QUIC_EXECUTION_PROFILE_TYPE_MAX_THROUGHPUT)) + { + RegConfig->ExecutionProfile = QUIC_EXECUTION_PROFILE_TYPE_MAX_THROUGHPUT; + } + else if (IS_SAME_TERM(eprofile, ATOM_QUIC_EXECUTION_PROFILE_TYPE_SCAVENGER)) + { + RegConfig->ExecutionProfile = QUIC_EXECUTION_PROFILE_TYPE_SCAVENGER; + } + else if (IS_SAME_TERM(eprofile, ATOM_QUIC_EXECUTION_PROFILE_TYPE_REAL_TIME)) + { + RegConfig->ExecutionProfile = QUIC_EXECUTION_PROFILE_TYPE_REAL_TIME; + } + else + { + return FALSE; + } + return TRUE; +} diff --git a/c_src/quicer_reg.h b/c_src/quicer_reg.h index 38444423..c326530d 100644 --- a/c_src/quicer_reg.h +++ b/c_src/quicer_reg.h @@ -17,6 +17,12 @@ limitations under the License. #define QUICER_REG_H_ #include +ERL_NIF_TERM +registration(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); + +ERL_NIF_TERM +deregistration(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); + ERL_NIF_TERM new_registration2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); diff --git a/src/quicer_app.erl b/src/quicer_app.erl index 13be524e..0b88baf4 100644 --- a/src/quicer_app.erl +++ b/src/quicer_app.erl @@ -22,7 +22,7 @@ start(_StartType, _StartArgs) -> quicer:open_lib(), - quicer:reg_open(application:get_env(quicer, profile, quic_execution_profile_low_latency)), + _ = quicer:reg_open(application:get_env(quicer, profile, quic_execution_profile_low_latency)), quicer_sup:start_link(). stop(_) -> diff --git a/test/quicer_SUITE.erl b/test/quicer_SUITE.erl index 07204289..4b986223 100644 --- a/test/quicer_SUITE.erl +++ b/test/quicer_SUITE.erl @@ -219,8 +219,12 @@ end_per_testcase(tc_close_lib_test, _Config) -> quicer:open_lib(); end_per_testcase(tc_lib_registration, _Config) -> quicer:reg_open(); +end_per_testcase(tc_lib_registration_1, _Config) -> + quicer:reg_open(); end_per_testcase(tc_lib_re_registration, _Config) -> quicer:reg_open(); +end_per_testcase(tc_lib_re_registration_neg, _Config) -> + quicer:reg_open(); end_per_testcase(tc_open_listener_neg_1, _Config) -> quicer:open_lib(), quicer:reg_open(); @@ -260,8 +264,8 @@ tc_open_lib_test(_Config) -> {ok, false} = quicer:open_lib(). tc_close_lib_test(_Config) -> + ok = quicer:reg_close(), {ok, false} = quicer:open_lib(), - %% @todo close reg before close lib ok = quicer:reg_close(), ok = quicer:close_lib(), ok = quicer:close_lib(), @@ -271,15 +275,20 @@ tc_close_lib_test(_Config) -> tc_lib_registration_neg(_Config) -> ok = quicer:close_lib(), {error, badarg} = quicer:reg_open(), - ok = quicer:reg_close(). + {error, badarg} = quicer:reg_close(). tc_lib_registration(_Config) -> quicer:open_lib(), - ok = quicer:reg_open(), + case quicer:reg_open() of + {error, badarg} -> + quicer:reg_close(); + ok -> + ok + end, ok = quicer:reg_close(). tc_lib_registration_1(_Config) -> - ok =quicer:reg_close(), + ok = quicer:reg_close(), {error, badarg} = quicer:reg_open(foo), ok = quicer:reg_open(quic_execution_profile_low_latency), ok = quicer:reg_close(), @@ -305,8 +314,7 @@ tc_lib_re_registration(_Config) -> tc_open_listener_inval_reg(Config) -> Port = select_port(), ok = quicer:reg_close(), - ok = quicer:close_lib(), - {error, config_error, reg_failed} = quicer:listen(Port, default_listen_opts(Config)), + {error, quic_registration} = quicer:listen(Port, default_listen_opts(Config)), quicer:open_lib(), quicer:reg_open(), ok. @@ -815,7 +823,7 @@ dgram_client_recv_loop(Conn, ReceivedOnStream, ReceivedViaDgram) -> receive {quic, <<"pong">>, Conn, Flag} when is_integer(Flag) -> dgram_client_recv_loop(Conn, ReceivedOnStream, true); - {quic, <<"pong">>, _Stream, Flag} -> + {quic, <<"pong">>, _Stream, _Flag} -> dgram_client_recv_loop(Conn, true, ReceivedViaDgram); {quic, dgram_state_changed, Conn, #{dgram_send_enabled := true, dgram_max_len := _Size}} -> dgram_client_recv_loop(Conn, ReceivedOnStream, ReceivedViaDgram);