Merge pull request #3110 from emqx/rm-stop-reason
Remove the 'stop_reason' field
This commit is contained in:
commit
6cd189fe88
|
@ -88,10 +88,10 @@
|
||||||
gc_state :: maybe(emqx_gc:gc_state()),
|
gc_state :: maybe(emqx_gc:gc_state()),
|
||||||
%% Stats Timer
|
%% Stats Timer
|
||||||
stats_timer :: disabled | maybe(reference()),
|
stats_timer :: disabled | maybe(reference()),
|
||||||
%% Idle Timer
|
|
||||||
idle_timer :: maybe(reference()),
|
|
||||||
%% Idle Timeout
|
%% Idle Timeout
|
||||||
idle_timeout :: integer()
|
idle_timeout :: integer(),
|
||||||
|
%% Idle Timer
|
||||||
|
idle_timer :: maybe(reference())
|
||||||
}).
|
}).
|
||||||
|
|
||||||
-type(state() :: #state{}).
|
-type(state() :: #state{}).
|
||||||
|
@ -208,8 +208,8 @@ init_state(Transport, Socket, Options) ->
|
||||||
channel = Channel,
|
channel = Channel,
|
||||||
gc_state = GcState,
|
gc_state = GcState,
|
||||||
stats_timer = StatsTimer,
|
stats_timer = StatsTimer,
|
||||||
idle_timer = IdleTimer,
|
idle_timeout = IdleTimeout,
|
||||||
idle_timeout = IdleTimeout
|
idle_timer = IdleTimer
|
||||||
}.
|
}.
|
||||||
|
|
||||||
run_loop(Parent, State = #state{transport = Transport,
|
run_loop(Parent, State = #state{transport = Transport,
|
||||||
|
|
|
@ -81,9 +81,7 @@
|
||||||
%% Idle Timeout
|
%% Idle Timeout
|
||||||
idle_timeout :: timeout(),
|
idle_timeout :: timeout(),
|
||||||
%% Idle Timer
|
%% Idle Timer
|
||||||
idle_timer :: reference(),
|
idle_timer :: reference()
|
||||||
%% The Stop Reason
|
|
||||||
stop_reason :: term()
|
|
||||||
}).
|
}).
|
||||||
|
|
||||||
-type(state() :: #state{}).
|
-type(state() :: #state{}).
|
||||||
|
@ -131,8 +129,10 @@ info(postponed, #state{postponed = Postponed}) ->
|
||||||
Postponed;
|
Postponed;
|
||||||
info(stats_timer, #state{stats_timer = TRef}) ->
|
info(stats_timer, #state{stats_timer = TRef}) ->
|
||||||
TRef;
|
TRef;
|
||||||
info(stop_reason, #state{stop_reason = Reason}) ->
|
info(idle_timeout, #state{idle_timeout = Timeout}) ->
|
||||||
Reason.
|
Timeout;
|
||||||
|
info(idle_timer, #state{idle_timer = TRef}) ->
|
||||||
|
TRef.
|
||||||
|
|
||||||
-spec(stats(pid()|state()) -> emqx_types:stats()).
|
-spec(stats(pid()|state()) -> emqx_types:stats()).
|
||||||
stats(WsPid) when is_pid(WsPid) ->
|
stats(WsPid) when is_pid(WsPid) ->
|
||||||
|
@ -318,8 +318,8 @@ websocket_close(Reason, State) ->
|
||||||
?LOG(debug, "Websocket closed due to ~p~n", [Reason]),
|
?LOG(debug, "Websocket closed due to ~p~n", [Reason]),
|
||||||
handle_info({sock_closed, Reason}, State).
|
handle_info({sock_closed, Reason}, State).
|
||||||
|
|
||||||
terminate(Error, _Req, #state{channel = Channel, stop_reason = Reason}) ->
|
terminate(Reason, _Req, #state{channel = Channel}) ->
|
||||||
?LOG(debug, "Terminated for ~p, error: ~p", [Reason, Error]),
|
?LOG(debug, "Terminated due to ~p", [Reason]),
|
||||||
emqx_channel:terminate(Reason, Channel).
|
emqx_channel:terminate(Reason, Channel).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -610,8 +610,7 @@ enqueue(Other, State = #state{postponed = Postponed}) ->
|
||||||
State#state{postponed = [Other|Postponed]}.
|
State#state{postponed = [Other|Postponed]}.
|
||||||
|
|
||||||
shutdown(Reason, State = #state{postponed = Postponed}) ->
|
shutdown(Reason, State = #state{postponed = Postponed}) ->
|
||||||
Postponed1 = [{shutdown, Reason}|Postponed],
|
return(State#state{postponed = [{shutdown, Reason}|Postponed]}).
|
||||||
return(State#state{postponed = Postponed1, stop_reason = Reason}).
|
|
||||||
|
|
||||||
return(State = #state{postponed = []}) ->
|
return(State = #state{postponed = []}) ->
|
||||||
{ok, State};
|
{ok, State};
|
||||||
|
|
|
@ -128,10 +128,6 @@ t_info_postponed(_) ->
|
||||||
St = ?ws_conn:postpone({active, false}, st()),
|
St = ?ws_conn:postpone({active, false}, st()),
|
||||||
?assertEqual([{active, false}], ?ws_conn:info(postponed, St)).
|
?assertEqual([{active, false}], ?ws_conn:info(postponed, St)).
|
||||||
|
|
||||||
t_info_stop_reason(_) ->
|
|
||||||
St = st(#{stop_reason => normal}),
|
|
||||||
?assertEqual(normal, ?ws_conn:info(stop_reason, St)).
|
|
||||||
|
|
||||||
t_stats(_) ->
|
t_stats(_) ->
|
||||||
WsPid = spawn(fun() ->
|
WsPid = spawn(fun() ->
|
||||||
receive {call, From, stats} ->
|
receive {call, From, stats} ->
|
||||||
|
@ -179,8 +175,7 @@ t_websocket_handle_pong(_) ->
|
||||||
{ok, St} = websocket_handle({pong, <<>>}, St).
|
{ok, St} = websocket_handle({pong, <<>>}, St).
|
||||||
|
|
||||||
t_websocket_handle_bad_frame(_) ->
|
t_websocket_handle_bad_frame(_) ->
|
||||||
{[{shutdown, unexpected_ws_frame}], St} = websocket_handle({badframe, <<>>}, st()),
|
{[{shutdown, unexpected_ws_frame}], _St} = websocket_handle({badframe, <<>>}, st()).
|
||||||
{shutdown, unexpected_ws_frame} = ?ws_conn:info(stop_reason, St).
|
|
||||||
|
|
||||||
t_websocket_info_call(_) ->
|
t_websocket_info_call(_) ->
|
||||||
From = {make_ref(), self()},
|
From = {make_ref(), self()},
|
||||||
|
@ -255,20 +250,16 @@ t_websocket_info_timeout_retry(_) ->
|
||||||
{ok, _St} = websocket_info({timeout, make_ref(), retry_delivery}, st()).
|
{ok, _St} = websocket_info({timeout, make_ref(), retry_delivery}, st()).
|
||||||
|
|
||||||
t_websocket_info_close(_) ->
|
t_websocket_info_close(_) ->
|
||||||
{[close], St} = websocket_info({close, sock_error}, st()),
|
{[close], _St} = websocket_info({close, sock_error}, st()).
|
||||||
?assertEqual({shutdown, sock_error}, ?ws_conn:info(stop_reason, St)).
|
|
||||||
|
|
||||||
t_websocket_info_shutdown(_) ->
|
t_websocket_info_shutdown(_) ->
|
||||||
{[{shutdown, reason}], St} = websocket_info({shutdown, reason}, st()),
|
{[{shutdown, reason}], _St} = websocket_info({shutdown, reason}, st()).
|
||||||
?assertEqual({shutdown, reason}, ?ws_conn:info(stop_reason, St)).
|
|
||||||
|
|
||||||
t_websocket_info_stop(_) ->
|
t_websocket_info_stop(_) ->
|
||||||
{[{shutdown, normal}], St} = websocket_info({stop, normal}, st()),
|
{[{shutdown, normal}], _St} = websocket_info({stop, normal}, st()).
|
||||||
?assertEqual(normal, ?ws_conn:info(stop_reason, St)).
|
|
||||||
|
|
||||||
t_websocket_close(_) ->
|
t_websocket_close(_) ->
|
||||||
{[{shutdown, badframe}], St} = websocket_close(badframe, st()),
|
{[{shutdown, badframe}], _St} = websocket_close(badframe, st()).
|
||||||
?assertEqual({shutdown, badframe}, ?ws_conn:info(stop_reason, St)).
|
|
||||||
|
|
||||||
t_handle_info_connack(_) ->
|
t_handle_info_connack(_) ->
|
||||||
ConnAck = ?CONNACK_PACKET(?RC_SUCCESS),
|
ConnAck = ?CONNACK_PACKET(?RC_SUCCESS),
|
||||||
|
@ -277,8 +268,7 @@ t_handle_info_connack(_) ->
|
||||||
?assertEqual(<<32,2,0,0>>, iolist_to_binary(IoData)).
|
?assertEqual(<<32,2,0,0>>, iolist_to_binary(IoData)).
|
||||||
|
|
||||||
t_handle_info_close(_) ->
|
t_handle_info_close(_) ->
|
||||||
{[close], St} = ?ws_conn:handle_info({close, protocol_error}, st()),
|
{[close], _St} = ?ws_conn:handle_info({close, protocol_error}, st()).
|
||||||
?assertEqual({shutdown, protocol_error}, ?ws_conn:info(stop_reason, St)).
|
|
||||||
|
|
||||||
t_handle_info_event(_) ->
|
t_handle_info_event(_) ->
|
||||||
ok = meck:new(emqx_cm, [passthrough, no_history]),
|
ok = meck:new(emqx_cm, [passthrough, no_history]),
|
||||||
|
@ -291,9 +281,8 @@ t_handle_info_event(_) ->
|
||||||
|
|
||||||
t_handle_timeout_idle_timeout(_) ->
|
t_handle_timeout_idle_timeout(_) ->
|
||||||
TRef = make_ref(),
|
TRef = make_ref(),
|
||||||
{[{shutdown, idle_timeout}], St} =
|
St = st(#{idle_timer => TRef}),
|
||||||
?ws_conn:handle_timeout(TRef, idle_timeout, st(#{idle_timer => TRef})),
|
{[{shutdown, idle_timeout}], _St} = ?ws_conn:handle_timeout(TRef, idle_timeout, St).
|
||||||
?assertEqual({shutdown, idle_timeout}, ?ws_conn:info(stop_reason, St)).
|
|
||||||
|
|
||||||
t_handle_timeout_keepalive(_) ->
|
t_handle_timeout_keepalive(_) ->
|
||||||
{ok, _St} = ?ws_conn:handle_timeout(make_ref(), keepalive, st()).
|
{ok, _St} = ?ws_conn:handle_timeout(make_ref(), keepalive, st()).
|
||||||
|
@ -359,8 +348,7 @@ t_enqueue(_) ->
|
||||||
[Packet] = ?ws_conn:info(postponed, St).
|
[Packet] = ?ws_conn:info(postponed, St).
|
||||||
|
|
||||||
t_shutdown(_) ->
|
t_shutdown(_) ->
|
||||||
{[{shutdown, closed}], St} = ?ws_conn:shutdown(closed, st()),
|
{[{shutdown, closed}], _St} = ?ws_conn:shutdown(closed, st()).
|
||||||
{shutdown, closed} = ?ws_conn:info(stop_reason, St).
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Helper functions
|
%% Helper functions
|
||||||
|
|
Loading…
Reference in New Issue