aboutsummaryrefslogtreecommitdiffstats
path: root/doc/src/manual/cowboy_websocket_handler.ezdoc
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-09-30 20:12:13 +0300
committerLoïc Hoguin <[email protected]>2014-09-30 20:12:13 +0300
commit0dc063ab7d94edb37c61f821b5d8e4c2da7f8ff1 (patch)
treeaaa71b552b0348fc403cc68ba8318e58f213d4fd /doc/src/manual/cowboy_websocket_handler.ezdoc
parent5ce4c2bfb40ecc4b687a2941e612025a1c4ff913 (diff)
downloadcowboy-0dc063ab7d94edb37c61f821b5d8e4c2da7f8ff1.tar.gz
cowboy-0dc063ab7d94edb37c61f821b5d8e4c2da7f8ff1.tar.bz2
cowboy-0dc063ab7d94edb37c61f821b5d8e4c2da7f8ff1.zip
Improve handler interface and documentation
This change simplifies a little more the sub protocols mechanism. Aliases have been removed. The renaming of loop handlers as long polling handlers has been reverted. Plain HTTP handlers now simply do their work in the init/2 callback. There is no specific code for them. Loop handlers now follow the same return value as Websocket, they use ok to continue and shutdown to stop. Terminate reasons for all handler types have been documented. The terminate callback is now appropriately called in all cases (or should be). Behaviors for all handler types have been moved in the module that implement them. This means that cowboy_handler replaces the cowboy_http_handler behavior, and similarly cowboy_loop replaces cowboy_loop_handler, cowboy_websocket replaces cowboy_websocket_handler. Finally cowboy_rest now has the start of a behavior in it and will have the full list of optional callbacks defined once Erlang 18.0 gets released. The guide has been reorganized and should be easier to follow.
Diffstat (limited to 'doc/src/manual/cowboy_websocket_handler.ezdoc')
-rw-r--r--doc/src/manual/cowboy_websocket_handler.ezdoc133
1 files changed, 0 insertions, 133 deletions
diff --git a/doc/src/manual/cowboy_websocket_handler.ezdoc b/doc/src/manual/cowboy_websocket_handler.ezdoc
deleted file mode 100644
index 0d31a54..0000000
--- a/doc/src/manual/cowboy_websocket_handler.ezdoc
+++ /dev/null
@@ -1,133 +0,0 @@
-::: cowboy_websocket_handler
-
-The `cowboy_websocket_handler` behaviour defines the interface used
-by Websocket handlers.
-
-The `init/3` and `websocket_init/3` callbacks will always be called,
-followed by zero or more calls to `websocket_handle/3` and
-`websocket_info/3`. The `websocket_terminate/3` will always
-be called last.
-
-:: Types
-
-None.
-
-:: Callbacks
-
-: init({TransportName, ProtocolName}, Req, Opts)
- -> {upgrade, protocol, cowboy_websocket}
- | {upgrade, protocol, cowboy_websocket, Req, Opts}
-
-Types:
-
-* TransportName = tcp | ssl | atom()
-* ProtocolName = http | atom()
-* Req = cowboy_req:req()
-* Opts = any()
-
-Upgrade the protocol to `cowboy_websocket`.
-
-: websocket_init(TransportName, Req, Opts)
- -> {ok, Req, State}
- | {ok, Req, State, hibernate}
- | {ok, Req, State, Timeout}
- | {ok, Req, State, Timeout, hibernate}
- | {shutdown, Req}
-
-Types:
-
-* TransportName = tcp | ssl | atom()
-* Req = cowboy_req:req()
-* Opts = any()
-* State = any()
-* Timeout = timeout()
-
-Initialize the state for this session.
-
-This function is called before the upgrade to Websocket occurs.
-It can be used to negotiate Websocket protocol extensions
-with the client. It will typically be used to register this process
-to an event manager or a message queue in order to receive
-the messages the handler wants to process.
-
-The connection will stay up for a duration of up to `Timeout`
-milliseconds after it last received data from the socket,
-at which point it will stop and close the connection.
-By default this value is set to `infinity`. It is recommended
-to either set this value or ensure by any other mechanism
-that the handler will be closed after a certain period of
-inactivity.
-
-The `hibernate` option will hibernate the process until it
-starts receiving either data from the Websocket connection
-or Erlang messages.
-
-The `shutdown` return value can be used to close the connection
-before upgrading to Websocket.
-
-: websocket_handle(InFrame, Req, State)
- -> {ok, Req, State}
- | {ok, Req, State, hibernate}
- | {reply, OutFrame | [OutFrame], Req, State}
- | {reply, OutFrame | [OutFrame], Req, State, hibernate}
- | {shutdown, Req, State}
-
-Types:
-
-* InFrame = {text | binary | ping | pong, binary()}
-* Req = cowboy_req:req()
-* State = any()
-* OutFrame = cowboy_websocket:frame()
-
-Handle the data received from the Websocket connection.
-
-This function will be called every time data is received
-from the Websocket connection.
-
-The `shutdown` return value can be used to close the
-connection. A close reply will also result in the connection
-being closed.
-
-The `hibernate` option will hibernate the process until
-it receives new data from the Websocket connection or an
-Erlang message.
-
-: websocket_info(Info, Req, State)
- -> {ok, Req, State}
- | {ok, Req, State, hibernate}
- | {reply, OutFrame | [OutFrame], Req, State}
- | {reply, OutFrame | [OutFrame], Req, State, hibernate}
- | {shutdown, Req, State}
-
-Types:
-
-* Info = any()
-* Req = cowboy_req:req()
-* State = any()
-* OutFrame = cowboy_websocket:frame()
-
-Handle the Erlang message received.
-
-This function will be called every time an Erlang message
-has been received. The message can be any Erlang term.
-
-The `shutdown` return value can be used to close the
-connection. A close reply will also result in the connection
-being closed.
-
-The `hibernate` option will hibernate the process until
-it receives another message or new data from the Websocket
-connection.
-
-: websocket_terminate(Reason, Req, State) -> ok
-
-Types:
-
-* Reason = {normal, shutdown | timeout} | {remote, closed} | {remote, cowboy_websocket:close_code(), binary()} | {error, badencoding | badframe | closed | atom()}
-* Req = cowboy_req:req()
-* State = any()
-
-Perform any necessary cleanup of the state.
-
-The connection will be closed and the process stopped right
-after this call.