2012-05-23 14:53:48 +02:00
|
|
|
%% Copyright (c) 2011-2012, Loïc Hoguin <essen@ninenines.eu>
|
2011-04-03 00:21:47 +02:00
|
|
|
%%
|
|
|
|
%% Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
%% purpose with or without fee is hereby granted, provided that the above
|
|
|
|
%% copyright notice and this permission notice appear in all copies.
|
|
|
|
%%
|
|
|
|
%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
2012-08-27 11:50:35 +02:00
|
|
|
%% @doc Convenience API to start and stop HTTP/HTTPS listeners.
|
2011-04-03 00:21:47 +02:00
|
|
|
-module(cowboy).
|
|
|
|
|
2012-08-27 11:50:35 +02:00
|
|
|
-export([start_http/4]).
|
|
|
|
-export([start_https/4]).
|
|
|
|
-export([stop_listener/1]).
|
|
|
|
|
|
|
|
%% @doc Start an HTTP listener.
|
|
|
|
-spec start_http(any(), non_neg_integer(), any(), any()) -> {ok, pid()}.
|
|
|
|
start_http(Ref, NbAcceptors, TransOpts, ProtoOpts)
|
|
|
|
when is_integer(NbAcceptors), NbAcceptors > 0 ->
|
|
|
|
ranch:start_listener(Ref, NbAcceptors,
|
2012-08-27 12:58:04 +02:00
|
|
|
ranch_tcp, TransOpts, cowboy_protocol, ProtoOpts).
|
2012-08-27 11:50:35 +02:00
|
|
|
|
|
|
|
%% @doc Start an HTTPS listener.
|
|
|
|
-spec start_https(any(), non_neg_integer(), any(), any()) -> {ok, pid()}.
|
|
|
|
start_https(Ref, NbAcceptors, TransOpts, ProtoOpts)
|
|
|
|
when is_integer(NbAcceptors), NbAcceptors > 0 ->
|
|
|
|
ranch:start_listener(Ref, NbAcceptors,
|
2012-08-27 12:58:04 +02:00
|
|
|
ranch_ssl, TransOpts, cowboy_protocol, ProtoOpts).
|
2012-08-27 11:50:35 +02:00
|
|
|
|
|
|
|
%% @doc Stop a listener.
|
|
|
|
-spec stop_listener(any()) -> ok.
|
2011-04-03 00:21:47 +02:00
|
|
|
stop_listener(Ref) ->
|
2012-08-27 11:50:35 +02:00
|
|
|
ranch:stop_listener(Ref).
|