aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorj.uhlig <[email protected]>2018-05-03 13:22:30 +0200
committerLoïc Hoguin <[email protected]>2018-05-07 13:11:16 +0200
commit301f582b97f82e7f7dc2d41bb575671bcc30215e (patch)
treed9cff0b381bb7189eb4ebee27438927d82e2b2ff /doc
parent7006c50c3ed6c3cbcb24e9e88a76ebd1aaf3a5f8 (diff)
downloadranch-301f582b97f82e7f7dc2d41bb575671bcc30215e.tar.gz
ranch-301f582b97f82e7f7dc2d41bb575671bcc30215e.tar.bz2
ranch-301f582b97f82e7f7dc2d41bb575671bcc30215e.zip
Replace gen_server with gen_statem in examples
Diffstat (limited to 'doc')
-rw-r--r--doc/src/guide/protocols.asciidoc18
1 files changed, 9 insertions, 9 deletions
diff --git a/doc/src/guide/protocols.asciidoc b/doc/src/guide/protocols.asciidoc
index b9a31f2..91f4b07 100644
--- a/doc/src/guide/protocols.asciidoc
+++ b/doc/src/guide/protocols.asciidoc
@@ -59,30 +59,30 @@ loop(Socket, Transport) ->
end.
----
-=== Using gen_server
+=== Using gen_statem
-Special processes like the ones that use the `gen_server` or `gen_fsm`
+Special processes like the ones that use the `gen_statem` or `gen_server`
behaviours have the particularity of having their `start_link` call not
return until the `init` function returns. This is problematic, because
you won't be able to call `ranch:accept_ack/1` from the `init` callback
as this would cause a deadlock to happen.
-Use the `gen_server:enter_loop/3` function. It allows you to start your process
+Use the `gen_statem:enter_loop/4` function. It allows you to start your process
normally (although it must be started with `proc_lib` like all special
processes), then perform any needed operations before falling back into
-the normal `gen_server` execution loop.
+the normal `gen_statem` execution loop.
-.Use a gen_server for protocol handling
+.Use a gen_statem for protocol handling
[source,erlang]
----
-module(my_protocol).
--behaviour(gen_server).
+-behaviour(gen_statem).
-behaviour(ranch_protocol).
-export([start_link/4]).
-export([init/1]).
-%% Exports of other gen_server callbacks here.
+%% Exports of other gen_statem callbacks here.
start_link(Ref, Socket, Transport, Opts) ->
{ok, proc_lib:spawn_link(?MODULE, init, [{Ref, Socket, Transport, Opts}])}.
@@ -91,9 +91,9 @@ init({Ref, Socket, Transport, _Opts = []}) ->
%% Perform any required state initialization here.
ok = ranch:accept_ack(Ref),
ok = Transport:setopts(Socket, [{active, once}]),
- gen_server:enter_loop(?MODULE, [], {state, Socket, Transport}).
+ gen_statem:enter_loop(?MODULE, [], state_name, {state_data, Socket, Transport}).
-%% Other gen_server callbacks here.
+%% Other gen_statem callbacks here.
----
Check the `tcp_reverse` example for a complete example.