aboutsummaryrefslogtreecommitdiffstats
path: root/guide
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-04-01 17:04:21 +0200
committerLoïc Hoguin <[email protected]>2013-04-01 17:04:21 +0200
commit109c63d0e76ca6248863932c7a9957f8093cfaf2 (patch)
tree12682f0ec90e57a31ef2e35d67e5440aa0335edb /guide
parent33db3b0d1aafcfbc9aadbad622a4014c021ef10c (diff)
downloadranch-109c63d0e76ca6248863932c7a9957f8093cfaf2.tar.gz
ranch-109c63d0e76ca6248863932c7a9957f8093cfaf2.tar.bz2
ranch-109c63d0e76ca6248863932c7a9957f8093cfaf2.zip
Remove ranch_listener and replace ListenerPid by Ref
We just don't need this process anymore. Less, simpler code! API changes: * Protocols start_link first argument is now Ref instead of ListenerPid * ranch:accept_ack/1 argument is now Ref instead of ListenerPid * ranch_listener:remove_connection/1 becomes ranch:remove_connection/1 and its argument is now Ref instead of ListenerPid Ref is the name of the listener given as first argument to start_listener/6.
Diffstat (limited to 'guide')
-rw-r--r--guide/listeners.md6
-rw-r--r--guide/protocols.md30
2 files changed, 18 insertions, 18 deletions
diff --git a/guide/listeners.md b/guide/listeners.md
index 1209706..a9ac4a0 100644
--- a/guide/listeners.md
+++ b/guide/listeners.md
@@ -162,11 +162,11 @@ connections are mostly waiting for messages, then they don't consume
much resources and can safely be removed from the count.
To remove the connection from the count, you must call the
-`ranch_listener:remove_connection/1` from within the connection process,
-with the listener pid as the only argument.
+`ranch:remove_connection/1` from within the connection process,
+with the name of the listener as the only argument.
``` erlang
-ranch_listener:remove_connection(ListenerPid).
+ranch:remove_connection(Ref).
```
As seen in the chapter covering protocols, this pid is received as the
diff --git a/guide/protocols.md b/guide/protocols.md
index 76995f9..ae9e8b6 100644
--- a/guide/protocols.md
+++ b/guide/protocols.md
@@ -13,7 +13,7 @@ Writing a protocol handler
All protocol handlers must implement the `ranch_protocol` behavior
which defines a single callback, `start_link/4`. This callback is
responsible for spawning a new process for handling the connection.
-It receives four arguments: the listener's pid, the socket, the
+It receives four arguments: the name of the listener, the socket, the
transport handler being used and the protocol options defined in
the call to `ranch:start_listener/6`. This callback must
return `{ok, Pid}`, with `Pid` the pid of the new process.
@@ -21,10 +21,10 @@ return `{ok, Pid}`, with `Pid` the pid of the new process.
The newly started process can then freely initialize itself. However,
it must call `ranch:accept_ack/1` before doing any socket operation.
This will ensure the connection process is the owner of the socket.
-It expects the listener's pid as argument.
+It expects the listener's name as argument.
``` erlang
-ok = ranch:accept_ack(ListenerPid).
+ok = ranch:accept_ack(Ref).
```
If your protocol code requires specific socket options, you should
@@ -42,12 +42,12 @@ in `examples/tcp_echo/`.
-export([start_link/4]).
-export([init/4]).
-start_link(ListenerPid, Socket, Transport, Opts) ->
- Pid = spawn_link(?MODULE, init, [ListenerPid, Socket, Transport, Opts]),
+start_link(Ref, Socket, Transport, Opts) ->
+ Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts]),
{ok, Pid}.
-init(ListenerPid, Socket, Transport, _Opts = []) ->
- ok = ranch:accept_ack(ListenerPid),
+init(Ref, Socket, Transport, _Opts = []) ->
+ ok = ranch:accept_ack(Ref),
loop(Socket, Transport).
loop(Socket, Transport) ->
@@ -86,13 +86,13 @@ the normal `gen_server` execution loop.
-export([init/1]).
%% Exports of other gen_server callbacks here.
-start_link(ListenerPid, Socket, Transport, Opts) ->
- proc_lib:start_link(?MODULE, [[ListenerPid, Socket, Transport, Opts]]).
+start_link(Ref, Socket, Transport, Opts) ->
+ proc_lib:start_link(?MODULE, [[Ref, Socket, Transport, Opts]]).
-init(ListenerPid, Socket, Transport, _Opts = []) ->
+init(Ref, Socket, Transport, _Opts = []) ->
ok = proc_lib:init_ack({ok, self()}),
%% Perform any required state initialization here.
- ok = ranch:accept_ack(ListenerPid),
+ ok = ranch:accept_ack(Ref),
ok = Transport:setopts(Socket, [{active, once}]),
gen_server:enter_loop(?MODULE, [], {state, Socket, Transport}).
@@ -110,11 +110,11 @@ ends. If you return a timeout value of `0` then the `gen_server` will call
%% Exports go here.
-init([ListenerPid, Socket, Transport]) ->
- {ok, {state, ListenerPid, Socket, Transport}, 0}.
+init([Ref, Socket, Transport]) ->
+ {ok, {state, Ref, Socket, Transport}, 0}.
-handle_info(timeout, State={state, ListenerPid, Socket, Transport}) ->
- ok = ranch:accept_ack(ListenerPid),
+handle_info(timeout, State={state, Ref, Socket, Transport}) ->
+ ok = ranch:accept_ack(Ref),
ok = Transport:setopts(Socket, [{active, once}]),
{noreply, State};
%% ...