aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_websocket_handler.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-12-02 21:37:24 +0100
committerLoïc Hoguin <[email protected]>2012-12-02 21:37:24 +0100
commit067958abd200c1c3fbc1956d4c6c30bc5efd344c (patch)
treefabfac36ff503b8a6fac1ad527d79ac440117e98 /src/cowboy_websocket_handler.erl
parent3e0e50731156647574e08e277cb39fe2fd63a86d (diff)
downloadcowboy-067958abd200c1c3fbc1956d4c6c30bc5efd344c.tar.gz
cowboy-067958abd200c1c3fbc1956d4c6c30bc5efd344c.tar.bz2
cowboy-067958abd200c1c3fbc1956d4c6c30bc5efd344c.zip
Add more frame types available in websocket replies
We can now reply empty close, ping and pong frames, or close frames with a payload. This means that we can send a frame and then close the connection in a single operation. If a close packet is sent, the connection is closed immediately, even if there was frames that remained to be sent. Cowboy will silently drop any extra frames in the list given as a reply.
Diffstat (limited to 'src/cowboy_websocket_handler.erl')
-rw-r--r--src/cowboy_websocket_handler.erl9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/cowboy_websocket_handler.erl b/src/cowboy_websocket_handler.erl
index 1b942fd..6d7f9de 100644
--- a/src/cowboy_websocket_handler.erl
+++ b/src/cowboy_websocket_handler.erl
@@ -50,7 +50,6 @@
-type opts() :: any().
-type state() :: any().
--type payload() :: {text | binary | ping | pong, binary()}.
-type terminate_reason() :: {normal, closed}
| {normal, timeout}
| {error, closed}
@@ -67,15 +66,15 @@
-callback websocket_handle({text | binary | ping | pong, binary()}, Req, State)
-> {ok, Req, State}
| {ok, Req, State, hibernate}
- | {reply, payload() | [payload()], Req, State}
- | {reply, payload() | [payload()], Req, State, hibernate}
+ | {reply, cowboy_websocket:frame() | [cowboy_websocket:frame()], Req, State}
+ | {reply, cowboy_websocket:frame() | [cowboy_websocket:frame()], Req, State, hibernate}
| {shutdown, Req, State}
when Req::cowboy_req:req(), State::state().
-callback websocket_info(any(), Req, State)
-> {ok, Req, State}
| {ok, Req, State, hibernate}
- | {reply, payload() | [payload()], Req, State}
- | {reply, payload() | [payload()], Req, State, hibernate}
+ | {reply, cowboy_websocket:frame() | [cowboy_websocket:frame()], Req, State}
+ | {reply, cowboy_websocket:frame() | [cowboy_websocket:frame()], Req, State, hibernate}
| {shutdown, Req, State}
when Req::cowboy_req:req(), State::state().
-callback websocket_terminate(terminate_reason(), cowboy_req:req(), state())