diff options
author | Loïc Hoguin <[email protected]> | 2018-09-21 14:04:20 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-09-21 15:01:57 +0200 |
commit | f810d8dd6496da713e7c70a5e146120de3695774 (patch) | |
tree | 0572028ff1ea5fdc6d3d4b081d75ebdbb6bf557d /src | |
parent | 6e784f1a454c6bdeab839d99d59dac992d430c97 (diff) | |
download | cowboy-f810d8dd6496da713e7c70a5e146120de3695774.tar.gz cowboy-f810d8dd6496da713e7c70a5e146120de3695774.tar.bz2 cowboy-f810d8dd6496da713e7c70a5e146120de3695774.zip |
Add the {active, boolean()} Websocket command
This command is currently not documented. It allows disabling
the reading of incoming data from the socket, and can be used
as a poor man's flow control.
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_websocket.erl | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl index 2aa56b9..0e88fc4 100644 --- a/src/cowboy_websocket.erl +++ b/src/cowboy_websocket.erl @@ -77,6 +77,7 @@ ref :: ranch:ref(), socket = undefined :: inet:socket() | {pid(), cowboy_stream:streamid()} | undefined, transport = undefined :: module() | undefined, + active = true :: boolean(), handler :: module(), key = undefined :: undefined | binary(), timeout = infinity :: timeout(), @@ -295,6 +296,8 @@ takeover(Parent, Ref, Socket, Transport, _Opts, Buffer, false -> before_loop(State, HandlerState, #ps_header{buffer=Buffer}) end. +before_loop(State=#state{active=false}, HandlerState, ParseState) -> + loop(State, HandlerState, ParseState); %% @todo We probably shouldn't do the setopts if we have not received a socket message. %% @todo We need to hibernate when HTTP/2 is used too. before_loop(State=#state{socket=Stream={Pid, _}, transport=undefined}, @@ -516,6 +519,8 @@ commands([], State, []) -> commands([], State, Data) -> Result = transport_send(State, nofin, lists:reverse(Data)), {Result, State}; +commands([{active, Active}|Tail], State, Data) when is_boolean(Active) -> + commands(Tail, State#state{active=Active}, Data); commands([Frame|Tail], State=#state{extensions=Extensions}, Data0) -> Data = [cow_ws:frame(Frame, Extensions)|Data0], case is_close_frame(Frame) of |