mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-15 20:50:24 +00:00
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.
This commit is contained in:
parent
56369d5c1a
commit
43d14b52cd
6 changed files with 50 additions and 24 deletions
|
@ -23,7 +23,7 @@
|
|||
%% </ul>
|
||||
-module(cowboy_http_websocket).
|
||||
|
||||
-export([upgrade/3]). %% API.
|
||||
-export([upgrade/4]). %% API.
|
||||
-export([handler_loop/4]). %% Internal.
|
||||
|
||||
-include("include/http.hrl").
|
||||
|
@ -45,8 +45,9 @@
|
|||
%% You do not need to call this function manually. To upgrade to the WebSocket
|
||||
%% protocol, you simply need to return <em>{upgrade, protocol, {@module}}</em>
|
||||
%% in your <em>cowboy_http_handler:init/3</em> handler function.
|
||||
-spec upgrade(module(), any(), #http_req{}) -> ok.
|
||||
upgrade(Handler, Opts, Req) ->
|
||||
-spec upgrade(pid(), module(), any(), #http_req{}) -> ok.
|
||||
upgrade(ListenerPid, Handler, Opts, Req) ->
|
||||
cowboy_listener:move_connection(ListenerPid, websocket, self()),
|
||||
EOP = binary:compile_pattern(<< 255 >>),
|
||||
case catch websocket_upgrade(#state{handler=Handler, opts=Opts, eop=EOP}, Req) of
|
||||
{ok, State, Req2} -> handler_init(State, Req2);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue