From bfff4b716420ff4428c7fbd093f4f09c1d912fea Mon Sep 17 00:00:00 2001 From: William Yang Date: Fri, 1 Dec 2023 15:29:38 +0100 Subject: [PATCH 1/3] feat: add a helper fun is_set --- src/quicer.erl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/quicer.erl b/src/quicer.erl index 454fd40c..0c955464 100644 --- a/src/quicer.erl +++ b/src/quicer.erl @@ -107,6 +107,7 @@ , new_fpbuffer/1 , update_fpbuffer/2 , defrag_fpbuffer/2 + , is_set/2 ]). %% Exports for test -export([ get_conn_rid/1 @@ -1219,6 +1220,12 @@ flush(QuicEventName, Handle) when is_atom(QuicEventName) -> %% Event must come, do not timeout end. +%% @doc Check if the bit mask is set in the integer. +-spec is_set(integer(), integer()) -> boolean(). +is_set(Num, BitMask) when is_integer(Num) + andalso is_integer(BitMask) -> + (Num band BitMask) =:= BitMask. + -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). From 0253fce8a50208915d1c9433b6283537581e3731 Mon Sep 17 00:00:00 2001 From: William Yang Date: Fri, 1 Dec 2023 15:30:08 +0100 Subject: [PATCH 2/3] ci(emqx): deprecate some OS releases --- .github/workflows/release.yaml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 8f3f1262..2d1d309b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -68,16 +68,13 @@ jobs: - ubuntu22.04 - ubuntu20.04 - ubuntu18.04 - - ubuntu16.04 - debian12 - debian11 - debian10 - - debian9 - amzn2023 - - el7 - - el8 - el9 - - alpine3.15.1 + - el8 + - el7 runs-on: ubuntu-latest steps: From f220f000401f8106792b677d6d2e0299ce97f631 Mon Sep 17 00:00:00 2001 From: William Yang Date: Fri, 1 Dec 2023 15:57:03 +0100 Subject: [PATCH 3/3] fix: avoid call msquic to send on closed stream use refcnt instead of mutex --- c_src/quicer_stream.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/c_src/quicer_stream.c b/c_src/quicer_stream.c index a8094347..cab3fc5a 100644 --- a/c_src/quicer_stream.c +++ b/c_src/quicer_stream.c @@ -652,10 +652,16 @@ send3(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) return ERROR_TUPLE_2(ATOM_BADARG); } + if (!get_stream_handle(s_ctx)) + { + return ERROR_TUPLE_2(ATOM_CLOSED); + } + QuicerStreamSendCTX *send_ctx = init_send_ctx(); if (!send_ctx) { - return ERROR_TUPLE_2(ATOM_ERROR_NOT_ENOUGH_MEMORY); + res = ERROR_TUPLE_2(ATOM_ERROR_NOT_ENOUGH_MEMORY); + goto Exit; } ErlNifBinary *bin = &send_ctx->bin; @@ -676,8 +682,8 @@ send3(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) } else { - destroy_send_ctx(send_ctx); - return ERROR_TUPLE_2(ATOM_BADARG); + res = ERROR_TUPLE_2(ATOM_BADARG); + goto ErrorExit; } ebin = enif_make_copy(send_ctx->env, ebin); @@ -685,35 +691,27 @@ send3(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) || enif_inspect_binary(send_ctx->env, ebin, bin)) || bin->size > UINT32_MAX) { - destroy_send_ctx(send_ctx); - return ERROR_TUPLE_2(ATOM_BADARG); - } - - enif_mutex_lock(s_ctx->lock); - if (!s_ctx->Stream) - { - res = ERROR_TUPLE_2(ATOM_CLOSED); + res = ERROR_TUPLE_2(ATOM_BADARG); goto ErrorExit; } - send_ctx->s_ctx = s_ctx; - - HQUIC Stream = s_ctx->Stream; - // // Allocates and builds the buffer to send over the stream. // - + send_ctx->s_ctx = s_ctx; assert(bin->data != NULL); send_ctx->Buffer.Buffer = (uint8_t *)bin->data; send_ctx->Buffer.Length = (uint32_t)bin->size; uint32_t bin_size = (uint32_t)bin->size; + assert(s_ctx->Stream); + QUIC_STATUS Status; // note, SendBuffer as sendcontext, free the buffer while message is sent // confirmed. - if (QUIC_FAILED(Status = MsQuic->StreamSend( - Stream, &send_ctx->Buffer, 1, sendflags, send_ctx))) + if (QUIC_FAILED( + Status = MsQuic->StreamSend( + s_ctx->Stream, &send_ctx->Buffer, 1, sendflags, send_ctx))) { res = ERROR_TUPLE_3(ATOM_STREAM_SEND_ERROR, ATOM_STATUS(Status)); goto ErrorExit; @@ -727,7 +725,7 @@ send3(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) ErrorExit: destroy_send_ctx(send_ctx); Exit: - enif_mutex_unlock(s_ctx->lock); + put_stream_handle(s_ctx); return res; }