aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ranch.erl8
-rw-r--r--src/ranch_acceptors_sup.erl4
-rw-r--r--src/ranch_server.erl22
3 files changed, 20 insertions, 14 deletions
diff --git a/src/ranch.erl b/src/ranch.erl
index 769447a..d2cd74b 100644
--- a/src/ranch.erl
+++ b/src/ranch.erl
@@ -19,6 +19,7 @@
-export([child_spec/6]).
-export([accept_ack/1]).
-export([remove_connection/1]).
+-export([get_addr/1]).
-export([get_port/1]).
-export([get_max_connections/1]).
-export([set_max_connections/2]).
@@ -105,9 +106,14 @@ remove_connection(Ref) ->
ConnsSup ! {remove_connection, Ref},
ok.
+-spec get_addr(ref()) -> {inet:ip_address(), inet:port_number()}.
+get_addr(Ref) ->
+ ranch_server:get_addr(Ref).
+
-spec get_port(ref()) -> inet:port_number().
get_port(Ref) ->
- ranch_server:get_port(Ref).
+ {_, Port} = get_addr(Ref),
+ Port.
-spec get_max_connections(ref()) -> max_conns().
get_max_connections(Ref) ->
diff --git a/src/ranch_acceptors_sup.erl b/src/ranch_acceptors_sup.erl
index 958bd59..5a3e93f 100644
--- a/src/ranch_acceptors_sup.erl
+++ b/src/ranch_acceptors_sup.erl
@@ -37,8 +37,8 @@ init([Ref, NbAcceptors, Transport, TransOpts]) ->
Socket ->
Socket
end,
- {ok, {_, Port}} = Transport:sockname(LSocket),
- ranch_server:set_port(Ref, Port),
+ {ok, Addr} = Transport:sockname(LSocket),
+ ranch_server:set_addr(Ref, Addr),
Procs = [
{{acceptor, self(), N}, {ranch_acceptor, start_link, [
LSocket, Transport, ConnsSup
diff --git a/src/ranch_server.erl b/src/ranch_server.erl
index c132fa3..55ebafb 100644
--- a/src/ranch_server.erl
+++ b/src/ranch_server.erl
@@ -21,8 +21,8 @@
-export([cleanup_listener_opts/1]).
-export([set_connections_sup/2]).
-export([get_connections_sup/1]).
--export([set_port/2]).
--export([get_port/1]).
+-export([set_addr/2]).
+-export([get_addr/1]).
-export([set_max_connections/2]).
-export([get_max_connections/1]).
-export([set_protocol_options/2]).
@@ -56,7 +56,7 @@ set_new_listener_opts(Ref, MaxConns, Opts) ->
-spec cleanup_listener_opts(ranch:ref()) -> ok.
cleanup_listener_opts(Ref) ->
- _ = ets:delete(?TAB, {port, Ref}),
+ _ = ets:delete(?TAB, {addr, Ref}),
_ = ets:delete(?TAB, {max_conns, Ref}),
_ = ets:delete(?TAB, {opts, Ref}),
ok.
@@ -70,13 +70,13 @@ set_connections_sup(Ref, Pid) ->
get_connections_sup(Ref) ->
ets:lookup_element(?TAB, {conns_sup, Ref}, 2).
--spec set_port(ranch:ref(), inet:port_number()) -> ok.
-set_port(Ref, Port) ->
- gen_server:call(?MODULE, {set_port, Ref, Port}).
+-spec set_addr(ranch:ref(), {inet:ip_address(), inet:port_number()}) -> ok.
+set_addr(Ref, Addr) ->
+ gen_server:call(?MODULE, {set_addr, Ref, Addr}).
--spec get_port(ranch:ref()) -> inet:port_number().
-get_port(Ref) ->
- ets:lookup_element(?TAB, {port, Ref}, 2).
+-spec get_addr(ranch:ref()) -> {inet:ip_address(), inet:port_number()}.
+get_addr(Ref) ->
+ ets:lookup_element(?TAB, {addr, Ref}, 2).
-spec set_max_connections(ranch:ref(), ranch:max_conns()) -> ok.
set_max_connections(Ref, MaxConnections) ->
@@ -119,8 +119,8 @@ handle_call({set_connections_sup, Ref, Pid}, _,
false ->
{reply, false, State}
end;
-handle_call({set_port, Ref, Port}, _, State) ->
- true = ets:insert(?TAB, {{port, Ref}, Port}),
+handle_call({set_addr, Ref, Addr}, _, State) ->
+ true = ets:insert(?TAB, {{addr, Ref}, Addr}),
{reply, ok, State};
handle_call({set_max_conns, Ref, MaxConns}, _, State) ->
ets:insert(?TAB, {{max_conns, Ref}, MaxConns}),