diff options
author | Loïc Hoguin <[email protected]> | 2011-08-10 20:28:30 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2011-08-10 20:28:30 +0200 |
commit | 43d14b52cd07dfd1121bbe6727a96dfd32304e47 (patch) | |
tree | 5b8d451d0decec8e75cf70c24e5c3fb54f51a65c /src/cowboy_http_protocol.erl | |
parent | 56369d5c1a0a3141e9d136b2f8010ff0e96bb26c (diff) | |
download | cowboy-43d14b52cd07dfd1121bbe6727a96dfd32304e47.tar.gz cowboy-43d14b52cd07dfd1121bbe6727a96dfd32304e47.tar.bz2 cowboy-43d14b52cd07dfd1121bbe6727a96dfd32304e47.zip |
Give the ListenerPid to the protocol on startup
Also sends a message 'shoot' that can be received by the protocol
to make sure Cowboy has had enough time to fully initialize the
socket. This message should be received before any socket-related
operations are performed.
WebSocket request connections are now moved from the pool 'default'
to the pool 'websocket', meaning we can have a lot of running
WebSockets despite having a low 'max_connections' setting.
Diffstat (limited to 'src/cowboy_http_protocol.erl')
-rw-r--r-- | src/cowboy_http_protocol.erl | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/cowboy_http_protocol.erl b/src/cowboy_http_protocol.erl index 421978b..a7da5bb 100644 --- a/src/cowboy_http_protocol.erl +++ b/src/cowboy_http_protocol.erl @@ -31,12 +31,13 @@ %% @see cowboy_http_handler -module(cowboy_http_protocol). --export([start_link/3]). %% API. --export([init/3, parse_request/1]). %% FSM. +-export([start_link/4]). %% API. +-export([init/4, parse_request/1]). %% FSM. -include("include/http.hrl"). -record(state, { + listener :: pid(), socket :: inet:socket(), transport :: module(), dispatch :: cowboy_dispatcher:dispatch_rules(), @@ -51,20 +52,21 @@ %% API. %% @doc Start an HTTP protocol process. --spec start_link(inet:socket(), module(), any()) -> {ok, pid()}. -start_link(Socket, Transport, Opts) -> - Pid = spawn_link(?MODULE, init, [Socket, Transport, Opts]), +-spec start_link(pid(), inet:socket(), module(), any()) -> {ok, pid()}. +start_link(ListenerPid, Socket, Transport, Opts) -> + Pid = spawn_link(?MODULE, init, [ListenerPid, Socket, Transport, Opts]), {ok, Pid}. %% FSM. %% @private --spec init(inet:socket(), module(), any()) -> ok. -init(Socket, Transport, Opts) -> +-spec init(pid(), inet:socket(), module(), any()) -> ok. +init(ListenerPid, Socket, Transport, Opts) -> Dispatch = proplists:get_value(dispatch, Opts, []), MaxEmptyLines = proplists:get_value(max_empty_lines, Opts, 5), Timeout = proplists:get_value(timeout, Opts, 5000), - wait_request(#state{socket=Socket, transport=Transport, + receive shoot -> ok end, + wait_request(#state{listener=ListenerPid, socket=Socket, transport=Transport, dispatch=Dispatch, max_empty_lines=MaxEmptyLines, timeout=Timeout}). %% @private @@ -189,14 +191,14 @@ dispatch(Req=#http_req{host=Host, path=Path}, end. -spec handler_init(#http_req{}, #state{}) -> ok. -handler_init(Req, State=#state{ +handler_init(Req, State=#state{listener=ListenerPid, transport=Transport, handler={Handler, Opts}}) -> try Handler:init({Transport:name(), http}, Req, Opts) of {ok, Req2, HandlerState} -> handler_loop(HandlerState, Req2, State); %% @todo {upgrade, transport, Module} {upgrade, protocol, Module} -> - Module:upgrade(Handler, Opts, Req) + Module:upgrade(ListenerPid, Handler, Opts, Req) catch Class:Reason -> error_terminate(500, State), error_logger:error_msg( |