Skip to content

Commit

Permalink
feat: bump to quicer 0.0.8
Browse files Browse the repository at this point in the history
- bump to quicer 0.0.8
- use right quicer cnt when judge if should send a ping
- ensure transport idle_timeout > MQTT idle timeout
  • Loading branch information
qzhuyan committed Aug 26, 2021
1 parent 321a676 commit d4c8ca7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -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 ++
Expand Down
9 changes: 8 additions & 1 deletion src/emqtt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/emqtt_quic.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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).
1 change: 1 addition & 0 deletions test/quic_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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">>, _, _, _, _} ->
Expand Down

0 comments on commit d4c8ca7

Please sign in to comment.