aboutsummaryrefslogtreecommitdiffstats
path: root/src/ranch_conns_sup.erl
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 /src/ranch_conns_sup.erl
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 'src/ranch_conns_sup.erl')
-rw-r--r--src/ranch_conns_sup.erl17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/ranch_conns_sup.erl b/src/ranch_conns_sup.erl
index 29b550f..eaa4d00 100644
--- a/src/ranch_conns_sup.erl
+++ b/src/ranch_conns_sup.erl
@@ -32,7 +32,7 @@
-record(state, {
parent = undefined :: pid(),
- listener_pid = undefined :: pid(),
+ ref :: any(),
transport = undefined :: module(),
protocol = undefined :: module(),
opts :: any(),
@@ -92,22 +92,21 @@ active_connections(SupPid) ->
init(Parent, Ref, Transport, Protocol) ->
process_flag(trap_exit, true),
ok = ranch_server:set_connections_sup(Ref, self()),
- ListenerPid = ranch_server:lookup_listener(Ref),
- {ok, MaxConns} = ranch_listener:get_max_connections(ListenerPid),
- {ok, Opts} = ranch_listener:get_protocol_options(ListenerPid),
+ MaxConns = ranch_server:get_max_connections(Ref),
+ Opts = ranch_server:get_protocol_options(Ref),
ok = proc_lib:init_ack(Parent, {ok, self()}),
- loop(#state{parent=Parent, listener_pid=ListenerPid, transport=Transport,
+ loop(#state{parent=Parent, ref=Ref, transport=Transport,
protocol=Protocol, opts=Opts, max_conns=MaxConns}, 0, 0, []).
-loop(State=#state{parent=Parent, listener_pid=ListenerPid,
+loop(State=#state{parent=Parent, ref=Ref,
transport=Transport, protocol=Protocol, opts=Opts,
max_conns=MaxConns}, CurConns, NbChildren, Sleepers) ->
receive
{?MODULE, start_protocol, To, Socket} ->
- case Protocol:start_link(ListenerPid, Socket, Transport, Opts) of
+ case Protocol:start_link(Ref, Socket, Transport, Opts) of
{ok, Pid} ->
Transport:controlling_process(Socket, Pid),
- Pid ! {shoot, ListenerPid},
+ Pid ! {shoot, Ref},
put(Pid, true),
CurConns2 = CurConns + 1,
if CurConns2 < MaxConns ->
@@ -126,7 +125,7 @@ loop(State=#state{parent=Parent, listener_pid=ListenerPid,
To ! {Tag, CurConns},
loop(State, CurConns, NbChildren, Sleepers);
%% Remove a connection from the count of connections.
- {remove_connection, ListenerPid} ->
+ {remove_connection, Ref} ->
loop(State, CurConns - 1, NbChildren, Sleepers);
%% Upgrade the max number of connections allowed concurrently.
%% We resume all sleeping acceptors if this number increases.