mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Merge remote-tracking branch 'jlouis/issue-71'
This commit is contained in:
commit
dbc577e69b
1 changed files with 18 additions and 6 deletions
|
@ -15,7 +15,7 @@
|
||||||
%% @doc Cowboy API to start and stop listeners.
|
%% @doc Cowboy API to start and stop listeners.
|
||||||
-module(cowboy).
|
-module(cowboy).
|
||||||
|
|
||||||
-export([start_listener/6, stop_listener/1]).
|
-export([start_listener/6, stop_listener/1, child_spec/6]).
|
||||||
|
|
||||||
%% @doc Start a listener for the given transport and protocol.
|
%% @doc Start a listener for the given transport and protocol.
|
||||||
%%
|
%%
|
||||||
|
@ -46,11 +46,8 @@
|
||||||
start_listener(Ref, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts)
|
start_listener(Ref, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts)
|
||||||
when is_integer(NbAcceptors) andalso is_atom(Transport)
|
when is_integer(NbAcceptors) andalso is_atom(Transport)
|
||||||
andalso is_atom(Protocol) ->
|
andalso is_atom(Protocol) ->
|
||||||
supervisor:start_child(cowboy_sup,
|
supervisor:start_child(cowboy_sup, child_spec(Ref, NbAcceptors,
|
||||||
{{cowboy_listener_sup, Ref}, {cowboy_listener_sup, start_link, [
|
Transport, TransOpts, Protocol, ProtoOpts)).
|
||||||
NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts
|
|
||||||
]},
|
|
||||||
permanent, 5000, supervisor, [cowboy_listener_sup]}).
|
|
||||||
|
|
||||||
%% @doc Stop a listener identified by <em>Ref</em>.
|
%% @doc Stop a listener identified by <em>Ref</em>.
|
||||||
%% @todo Currently request processes aren't terminated with the listener.
|
%% @todo Currently request processes aren't terminated with the listener.
|
||||||
|
@ -62,3 +59,18 @@ stop_listener(Ref) ->
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%% @doc Return a child spec suitable for embedding.
|
||||||
|
%% When you want to embed cowboy in another application, you can use this
|
||||||
|
%% function to create a <em>ChildSpec</em> suitable for use in a supervisor.
|
||||||
|
%% The parameters are the same as in <em>start_listener/6</em> but rather
|
||||||
|
%% than hooking the listener to the cowboy internal supervisor, it just returns
|
||||||
|
%% the spec.
|
||||||
|
-spec child_spec(any(), non_neg_integer(), module(), any(), module(), any())
|
||||||
|
-> supervisor:child_spec().
|
||||||
|
child_spec(Ref, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts)
|
||||||
|
when is_integer(NbAcceptors) andalso is_atom(Transport)
|
||||||
|
andalso is_atom(Protocol) ->
|
||||||
|
{{cowboy_listener_sup, Ref}, {cowboy_listener_sup, start_link, [
|
||||||
|
NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts
|
||||||
|
]}, permanent, 5000, supervisor, [cowboy_listener_sup]}.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue