aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-12-04 11:33:57 +0100
committerLoïc Hoguin <[email protected]>2019-12-04 11:33:57 +0100
commit8241791a3ea19deeaaa5d80252e69a958227a1d8 (patch)
tree547e112c14b5b95e7bb7b795daf4452f0d29ef37
parentcd7870df151a8686c6d204f9972f9032494c44d4 (diff)
downloadcowboy-8241791a3ea19deeaaa5d80252e69a958227a1d8.tar.gz
cowboy-8241791a3ea19deeaaa5d80252e69a958227a1d8.tar.bz2
cowboy-8241791a3ea19deeaaa5d80252e69a958227a1d8.zip
Use active,N for the linger loop as well
-rw-r--r--src/cowboy_http.erl39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index 7cbecef..f64cc5b 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -1432,38 +1432,41 @@ terminate_linger(State=#state{socket=Socket, transport=Transport, opts=Opts}) ->
0 ->
ok;
infinity ->
- terminate_linger_loop(State, undefined);
+ terminate_linger_before_loop(State, undefined, Transport:messages());
Timeout ->
TimerRef = erlang:start_timer(Timeout, self(), linger_timeout),
- terminate_linger_loop(State, TimerRef)
+ terminate_linger_before_loop(State, TimerRef, Transport:messages())
end;
{error, _} ->
ok
end.
-terminate_linger_loop(State=#state{socket=Socket, transport=Transport}, TimerRef) ->
- Messages = Transport:messages(),
+terminate_linger_before_loop(State=#state{socket=Socket, transport=Transport}, TimerRef, Messages) ->
%% We may already have a message in the mailbox when we do this
%% but it's OK because we are shutting down anyway.
- %% @todo Use active,N here as well.
- case Transport:setopts(Socket, [{active, once}]) of
+ case Transport:setopts(Socket, [{active, 100}]) of
ok ->
- receive
- {OK, Socket, _} when OK =:= element(1, Messages) ->
- terminate_linger_loop(State, TimerRef);
- {Closed, Socket} when Closed =:= element(2, Messages) ->
- ok;
- {Error, Socket, _} when Error =:= element(3, Messages) ->
- ok;
- {timeout, TimerRef, linger_timeout} ->
- ok;
- _ ->
- terminate_linger_loop(State, TimerRef)
- end;
+ terminate_linger_loop(State, TimerRef, Messages);
{error, _} ->
ok
end.
+terminate_linger_loop(State=#state{socket=Socket}, TimerRef, Messages) ->
+ receive
+ {OK, Socket, _} when OK =:= element(1, Messages) ->
+ terminate_linger_loop(State, TimerRef, Messages);
+ {Closed, Socket} when Closed =:= element(2, Messages) ->
+ ok;
+ {Error, Socket, _} when Error =:= element(3, Messages) ->
+ ok;
+ {Passive, Socket} when Passive =:= tcp_passive; Passive =:= ssl_passive ->
+ terminate_linger_before_loop(State, TimerRef, Messages);
+ {timeout, TimerRef, linger_timeout} ->
+ ok;
+ _ ->
+ terminate_linger_loop(State, TimerRef, Messages)
+ end.
+
%% System callbacks.
-spec system_continue(_, _, #state{}) -> ok.