aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_websocket.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/cowboy_websocket.erl')
-rw-r--r--src/cowboy_websocket.erl20
1 files changed, 5 insertions, 15 deletions
diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl
index 40046e1..98e25e6 100644
--- a/src/cowboy_websocket.erl
+++ b/src/cowboy_websocket.erl
@@ -1,4 +1,4 @@
-%% Copyright (c) 2011-2013, Loïc Hoguin <[email protected]>
+%% Copyright (c) 2011-2014, Loïc Hoguin <[email protected]>
%%
%% Permission to use, copy, modify, and/or distribute this software for any
%% purpose with or without fee is hereby granted, provided that the above
@@ -12,8 +12,6 @@
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-%% @doc Websocket protocol implementation.
-%%
%% Cowboy supports versions 7 through 17 of the Websocket drafts.
%% It also supports RFC6455, the proposed standard for Websocket.
-module(cowboy_websocket).
@@ -23,10 +21,7 @@
%% @todo Remove when we support only R16B+.
-compile(nowarn_deprecated_function).
-%% API.
-export([upgrade/4]).
-
-%% Internal.
-export([handler_loop/4]).
-type close_code() :: 1000..4999.
@@ -42,6 +37,8 @@
-type frag_state() :: undefined
| {nofin, opcode(), binary()} | {fin, opcode(), binary()}.
-type rsv() :: << _:3 >>.
+-type terminate_reason() :: {normal | error | remote, atom()}
+ | {remote, close_code(), binary()}.
-record(state, {
env :: cowboy_middleware:env(),
@@ -60,11 +57,6 @@
deflate_state :: undefined | port()
}).
-%% @doc Upgrade an HTTP request to the Websocket protocol.
-%%
-%% 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(Req, Env, module(), any())
-> {ok, Req, Env} | {error, 400, Req}
| {suspend, module(), atom(), [any()]}
@@ -213,7 +205,6 @@ handler_loop_timeout(State=#state{timeout=Timeout, timeout_ref=PrevRef}) ->
TRef = erlang:start_timer(Timeout, self(), ?MODULE),
State#state{timeout_ref=TRef}.
-%% @private
-spec handler_loop(#state{}, Req, any(), binary())
-> {ok, Req, cowboy_middleware:env()}
| {suspend, module(), atom(), [any()]}
@@ -730,8 +721,7 @@ websocket_send_many([Frame|Tail], State) ->
{Error, State2} -> {Error, State2}
end.
--spec websocket_close(#state{}, Req, any(),
- {atom(), atom()} | {remote, close_code(), binary()})
+-spec websocket_close(#state{}, Req, any(), terminate_reason())
-> {ok, Req, cowboy_middleware:env()}
when Req::cowboy_req:req().
websocket_close(State=#state{socket=Socket, transport=Transport},
@@ -752,7 +742,7 @@ websocket_close(State=#state{socket=Socket, transport=Transport},
end,
handler_terminate(State, Req, HandlerState, Reason).
--spec handler_terminate(#state{}, Req, any(), atom() | {atom(), atom()})
+-spec handler_terminate(#state{}, Req, any(), terminate_reason())
-> {ok, Req, cowboy_middleware:env()}
when Req::cowboy_req:req().
handler_terminate(#state{env=Env, handler=Handler},