From d4c8ca7fc47395735475f7a5089446a7d3ac387a Mon Sep 17 00:00:00 2001 From: William Yang Date: Thu, 26 Aug 2021 09:49:03 +0200 Subject: [PATCH] feat: bump to quicer 0.0.8 - bump to quicer 0.0.8 - use right quicer cnt when judge if should send a ping - ensure transport idle_timeout > MQTT idle timeout --- rebar.config.script | 2 +- src/emqtt.erl | 9 ++++++++- src/emqtt_quic.erl | 5 +++-- test/quic_server.erl | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/rebar.config.script b/rebar.config.script index 05b85a74..4807336b 100644 --- a/rebar.config.script +++ b/rebar.config.script @@ -40,7 +40,7 @@ Profiles1 = lists:keystore(emqtt, 1, Profiles, {emqtt, NewRelx(emqtt, Profiles)} Profiles2 = lists:keystore(emqtt_pkg, 1, Profiles1, {emqtt_pkg, NewRelx(emqtt_pkg, Profiles1)}), NewConfig = lists:keystore(profiles, 1, CONFIG, {profiles, Profiles2}), -Quicer = {quicer, {git, "https://github.com/emqx/quic.git", {tag, "0.0.6"}}}, +Quicer = {quicer, {git, "https://github.com/emqx/quic.git", {tag, "0.0.8"}}}, ExtraDeps = fun(C) -> {deps, Deps0} = lists:keyfind(deps, 1, C), Deps = Deps0 ++ diff --git a/src/emqtt.erl b/src/emqtt.erl index 2ea81e74..6e28836b 100644 --- a/src/emqtt.erl +++ b/src/emqtt.erl @@ -1067,11 +1067,18 @@ code_change(_Vsn, State, Data, _Extra) -> %%-------------------------------------------------------------------- %% Internal functions %%-------------------------------------------------------------------- +should_ping(emqtt_quic, Sock) -> + case emqtt_quic:getstat(Sock, [send_cnt]) of + {ok, [{send_cnt, V}]} -> + V == put(quic_send_cnt, V) orelse V == undefined; + Err -> + Err + end; should_ping(ConnMod, Sock) -> case ConnMod:getstat(Sock, [send_oct]) of {ok, [{send_oct, Val}]} -> - OldVal = get(send_oct), put(send_oct, Val), + OldVal = put(send_oct, Val), OldVal == undefined orelse OldVal == Val; Error = {error, _Reason} -> Error diff --git a/src/emqtt_quic.erl b/src/emqtt_quic.erl index f9bfb13b..4ff761f6 100644 --- a/src/emqtt_quic.erl +++ b/src/emqtt_quic.erl @@ -28,8 +28,9 @@ ]). connect(Host, Port, Opts, Timeout) -> + KeepAlive = proplists:get_value(keepalive, Opts, 60), ConnOpts = [ {alpn, ["mqtt"]} - , {idle_timeout_ms, 60000} + , {idle_timeout_ms, timer:seconds(KeepAlive * 3)} , {peer_unidi_stream_count, 1} , {peer_bidi_stream_count, 10} | Opts], @@ -58,7 +59,7 @@ setopts(Stream, Opts) -> ok. close(Stream) -> - quicer:async_close_stream(Stream). + quicer:close_stream(Stream, 1000). sockname(H) -> quicer:sockname(H). diff --git a/test/quic_server.erl b/test/quic_server.erl index 0b29a038..bc045466 100644 --- a/test/quic_server.erl +++ b/test/quic_server.erl @@ -36,6 +36,7 @@ server_loop(L) -> after 0 -> case quicer:accept(L, [], 30000) of {ok, Conn} -> + {ok, Conn} = quicer:handshake(Conn, 1000), {ok, Stm} = quicer:accept_stream(Conn, []), receive {quic, <<"ping">>, _, _, _, _} ->