diff options
Diffstat (limited to 'src/cowboy_acceptor.erl')
-rw-r--r-- | src/cowboy_acceptor.erl | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/cowboy_acceptor.erl b/src/cowboy_acceptor.erl index d46e212..29f7c09 100644 --- a/src/cowboy_acceptor.erl +++ b/src/cowboy_acceptor.erl @@ -16,7 +16,7 @@ -module(cowboy_acceptor). -export([start_link/6]). %% API. --export([acceptor/6]). %% Internal. +-export([acceptor/7]). %% Internal. %% API. @@ -25,27 +25,33 @@ start_link(LSocket, Transport, Protocol, Opts, ListenerPid, ReqsSup) -> Pid = spawn_link(?MODULE, acceptor, - [LSocket, Transport, Protocol, Opts, ListenerPid, ReqsSup]), + [LSocket, Transport, Protocol, Opts, 1, ListenerPid, ReqsSup]), {ok, Pid}. %% Internal. -spec acceptor(inet:socket(), module(), module(), any(), - pid(), pid()) -> no_return(). -acceptor(LSocket, Transport, Protocol, Opts, ListenerPid, ReqsSup) -> - case Transport:accept(LSocket, 2000) of + non_neg_integer(), pid(), pid()) -> no_return(). +acceptor(LSocket, Transport, Protocol, Opts, OptsVsn, ListenerPid, ReqsSup) -> + Res = case Transport:accept(LSocket, 2000) of {ok, CSocket} -> {ok, Pid} = supervisor:start_child(ReqsSup, [ListenerPid, CSocket, Transport, Protocol, Opts]), Transport:controlling_process(CSocket, Pid), - ok = cowboy_listener:add_connection(ListenerPid, - default, Pid); + cowboy_listener:add_connection(ListenerPid, + default, Pid, OptsVsn); {error, timeout} -> - ignore; + ok; {error, _Reason} -> %% @todo Probably do something here. If the socket was closed, %% we may want to try and listen again on the port? - ignore + ok end, - ?MODULE:acceptor(LSocket, Transport, Protocol, Opts, - ListenerPid, ReqsSup). + case Res of + ok -> + ?MODULE:acceptor(LSocket, Transport, Protocol, + Opts, OptsVsn, ListenerPid, ReqsSup); + {upgrade, Opts2, OptsVsn2} -> + ?MODULE:acceptor(LSocket, Transport, Protocol, + Opts2, OptsVsn2, ListenerPid, ReqsSup) + end. |