mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Use active,N for the linger loop as well
This commit is contained in:
parent
cd7870df15
commit
8241791a3e
1 changed files with 21 additions and 18 deletions
|
@ -1432,36 +1432,39 @@ terminate_linger(State=#state{socket=Socket, transport=Transport, opts=Opts}) ->
|
||||||
0 ->
|
0 ->
|
||||||
ok;
|
ok;
|
||||||
infinity ->
|
infinity ->
|
||||||
terminate_linger_loop(State, undefined);
|
terminate_linger_before_loop(State, undefined, Transport:messages());
|
||||||
Timeout ->
|
Timeout ->
|
||||||
TimerRef = erlang:start_timer(Timeout, self(), linger_timeout),
|
TimerRef = erlang:start_timer(Timeout, self(), linger_timeout),
|
||||||
terminate_linger_loop(State, TimerRef)
|
terminate_linger_before_loop(State, TimerRef, Transport:messages())
|
||||||
end;
|
end;
|
||||||
{error, _} ->
|
{error, _} ->
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
terminate_linger_loop(State=#state{socket=Socket, transport=Transport}, TimerRef) ->
|
terminate_linger_before_loop(State=#state{socket=Socket, transport=Transport}, TimerRef, Messages) ->
|
||||||
Messages = Transport:messages(),
|
|
||||||
%% We may already have a message in the mailbox when we do this
|
%% We may already have a message in the mailbox when we do this
|
||||||
%% but it's OK because we are shutting down anyway.
|
%% but it's OK because we are shutting down anyway.
|
||||||
%% @todo Use active,N here as well.
|
case Transport:setopts(Socket, [{active, 100}]) of
|
||||||
case Transport:setopts(Socket, [{active, once}]) of
|
|
||||||
ok ->
|
ok ->
|
||||||
|
terminate_linger_loop(State, TimerRef, Messages);
|
||||||
|
{error, _} ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
|
terminate_linger_loop(State=#state{socket=Socket}, TimerRef, Messages) ->
|
||||||
receive
|
receive
|
||||||
{OK, Socket, _} when OK =:= element(1, Messages) ->
|
{OK, Socket, _} when OK =:= element(1, Messages) ->
|
||||||
terminate_linger_loop(State, TimerRef);
|
terminate_linger_loop(State, TimerRef, Messages);
|
||||||
{Closed, Socket} when Closed =:= element(2, Messages) ->
|
{Closed, Socket} when Closed =:= element(2, Messages) ->
|
||||||
ok;
|
ok;
|
||||||
{Error, Socket, _} when Error =:= element(3, Messages) ->
|
{Error, Socket, _} when Error =:= element(3, Messages) ->
|
||||||
ok;
|
ok;
|
||||||
|
{Passive, Socket} when Passive =:= tcp_passive; Passive =:= ssl_passive ->
|
||||||
|
terminate_linger_before_loop(State, TimerRef, Messages);
|
||||||
{timeout, TimerRef, linger_timeout} ->
|
{timeout, TimerRef, linger_timeout} ->
|
||||||
ok;
|
ok;
|
||||||
_ ->
|
_ ->
|
||||||
terminate_linger_loop(State, TimerRef)
|
terminate_linger_loop(State, TimerRef, Messages)
|
||||||
end;
|
|
||||||
{error, _} ->
|
|
||||||
ok
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% System callbacks.
|
%% System callbacks.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue