aboutsummaryrefslogtreecommitdiffstats
path: root/src/ranch.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-07-24 12:58:54 +0200
committerLoïc Hoguin <[email protected]>2012-07-25 10:05:15 +0200
commitb72fe3e67e65c66d979a9651ebc815bdc553601c (patch)
treeb6014dcc9ed930c885851d0c56b200612dc77738 /src/ranch.erl
parented50a5556a788a9780b5a8f85764b509338c1073 (diff)
downloadranch-b72fe3e67e65c66d979a9651ebc815bdc553601c.tar.gz
ranch-b72fe3e67e65c66d979a9651ebc815bdc553601c.tar.bz2
ranch-b72fe3e67e65c66d979a9651ebc815bdc553601c.zip
Introduce the ranch_server registry, make it handle listeners
Diffstat (limited to 'src/ranch.erl')
-rw-r--r--src/ranch.erl20
1 files changed, 4 insertions, 16 deletions
diff --git a/src/ranch.erl b/src/ranch.erl
index 3f07df7..3360154 100644
--- a/src/ranch.erl
+++ b/src/ranch.erl
@@ -78,7 +78,7 @@ child_spec(Ref, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts)
when is_integer(NbAcceptors) andalso is_atom(Transport)
andalso is_atom(Protocol) ->
{{ranch_listener_sup, Ref}, {ranch_listener_sup, start_link, [
- NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts
+ Ref, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts
]}, permanent, 5000, supervisor, [ranch_listener_sup]}.
%% @doc Acknowledge the accepted connection.
@@ -92,14 +92,14 @@ accept_ack(ListenerPid) ->
%% @doc Return the listener's port.
-spec get_port(any()) -> inet:port_number().
get_port(Ref) ->
- ListenerPid = ref_to_listener_pid(Ref),
+ ListenerPid = ranch_server:lookup_listener(Ref),
{ok, Port} = ranch_listener:get_port(ListenerPid),
Port.
%% @doc Return the current protocol options for the given listener.
-spec get_protocol_options(any()) -> any().
get_protocol_options(Ref) ->
- ListenerPid = ref_to_listener_pid(Ref),
+ ListenerPid = ranch_server:lookup_listener(Ref),
{ok, ProtoOpts} = ranch_listener:get_protocol_options(ListenerPid),
ProtoOpts.
@@ -110,17 +110,5 @@ get_protocol_options(Ref) ->
%% no effect on the currently opened connections.
-spec set_protocol_options(any(), any()) -> ok.
set_protocol_options(Ref, ProtoOpts) ->
- ListenerPid = ref_to_listener_pid(Ref),
+ ListenerPid = ranch_server:lookup_listener(Ref),
ok = ranch_listener:set_protocol_options(ListenerPid, ProtoOpts).
-
-%% Internal.
-
--spec ref_to_listener_pid(any()) -> pid().
-ref_to_listener_pid(Ref) ->
- Children = supervisor:which_children(ranch_sup),
- {_, ListenerSupPid, _, _} = lists:keyfind(
- {ranch_listener_sup, Ref}, 1, Children),
- ListenerSupChildren = supervisor:which_children(ListenerSupPid),
- {_, ListenerPid, _, _} = lists:keyfind(
- ranch_listener, 1, ListenerSupChildren),
- ListenerPid.