mirror of
https://github.com/valitydev/woody_erlang.git
synced 2024-11-06 02:15:19 +00:00
MSPF-622: add get_addr/2 for woody_server (#148)
This commit is contained in:
parent
3b76622054
commit
58f56b4624
@ -5,6 +5,7 @@
|
||||
|
||||
%% API
|
||||
-export([child_spec/2]).
|
||||
-export([get_addr/2]).
|
||||
|
||||
%% Types
|
||||
-type options() :: #{
|
||||
@ -21,6 +22,7 @@
|
||||
|
||||
%% Behaviour definition
|
||||
-callback child_spec(_Id, options()) -> supervisor:child_spec().
|
||||
-callback get_addr(_Id) -> {inet:ip_address(), inet:port_number()}.
|
||||
|
||||
%%
|
||||
%% API
|
||||
@ -30,3 +32,9 @@
|
||||
child_spec(Id, Options) ->
|
||||
ProtocolHandler = woody_util:get_protocol_handler(server, Options),
|
||||
ProtocolHandler:child_spec(Id, Options).
|
||||
|
||||
-spec get_addr(_Id, options()) ->
|
||||
{inet:ip_address(), inet:port_number()}.
|
||||
get_addr(Id, Options) ->
|
||||
ProtocolHandler = woody_util:get_protocol_handler(server, Options),
|
||||
ProtocolHandler:get_addr(Id).
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
%% woody_server callback
|
||||
-export([child_spec/2]).
|
||||
-export([get_addr/1]).
|
||||
|
||||
%% API
|
||||
-export([get_routes/1]).
|
||||
@ -112,11 +113,19 @@
|
||||
child_spec(Id, Opts) ->
|
||||
{Transport, TransportOpts} = get_socket_transport(Opts),
|
||||
CowboyOpts = get_cowboy_config(Opts),
|
||||
RanchRef = {?MODULE, Id},
|
||||
RanchRef = create_ranch_ref(Id),
|
||||
DrainSpec = make_drain_childspec(RanchRef, Opts),
|
||||
RanchSpec = ranch:child_spec(RanchRef, Transport, TransportOpts, cowboy_clear, CowboyOpts),
|
||||
make_server_childspec(Id, [RanchSpec, DrainSpec]).
|
||||
|
||||
-spec get_addr(atom()) ->
|
||||
{inet:ip_address(), inet:port_number()}.
|
||||
get_addr(Id) ->
|
||||
ranch:get_addr(create_ranch_ref(Id)).
|
||||
|
||||
create_ranch_ref(Id) ->
|
||||
{?MODULE, Id}.
|
||||
|
||||
make_drain_childspec(Ref, Opts) ->
|
||||
ShutdownTimeout = maps:get(shutdown_timeout, Opts, ?DEFAULT_SHUTDOWN_TIMEOUT),
|
||||
DrainOpts = #{shutdown => ShutdownTimeout, ranch_ref => Ref},
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
%% woody_server callback
|
||||
-export([child_spec/2]).
|
||||
-export([get_addr/1]).
|
||||
|
||||
%% API
|
||||
-export([get_routes/1]).
|
||||
@ -120,11 +121,19 @@
|
||||
child_spec(Id, Opts) ->
|
||||
{Transport, TransportOpts} = get_socket_transport(Opts),
|
||||
CowboyOpts = get_cowboy_config(Opts),
|
||||
RanchRef = {?MODULE, Id},
|
||||
RanchRef = create_ranch_ref(Id),
|
||||
DrainSpec = make_drain_childspec(RanchRef, Opts),
|
||||
RanchSpec = ranch:child_spec(RanchRef, Transport, TransportOpts, cowboy_clear, CowboyOpts),
|
||||
make_server_childspec(Id, [RanchSpec, DrainSpec]).
|
||||
|
||||
-spec get_addr(atom()) ->
|
||||
{inet:ip_address(), inet:port_number()}.
|
||||
get_addr(Id) ->
|
||||
ranch:get_addr(create_ranch_ref(Id)).
|
||||
|
||||
create_ranch_ref(Id) ->
|
||||
{?MODULE, Id}.
|
||||
|
||||
make_drain_childspec(Ref, Opts) ->
|
||||
ShutdownTimeout = maps:get(shutdown_timeout, Opts, ?DEFAULT_SHUTDOWN_TIMEOUT),
|
||||
DrainOpts = #{shutdown => ShutdownTimeout, ranch_ref => Ref},
|
||||
|
Loading…
Reference in New Issue
Block a user