cowboy.erl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. %% Copyright (c) 2011-2013, Loïc Hoguin <essen@ninenines.eu>
  2. %%
  3. %% Permission to use, copy, modify, and/or distribute this software for any
  4. %% purpose with or without fee is hereby granted, provided that the above
  5. %% copyright notice and this permission notice appear in all copies.
  6. %%
  7. %% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. %% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. %% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. %% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. %% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. %% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. %% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. %% @doc Convenience API to start and stop HTTP/HTTPS listeners.
  15. -module(cowboy).
  16. -export([start_http/4]).
  17. -export([start_https/4]).
  18. -export([stop_listener/1]).
  19. %% @doc Start an HTTP listener.
  20. -spec start_http(any(), non_neg_integer(), any(), any()) -> {ok, pid()}.
  21. start_http(Ref, NbAcceptors, TransOpts, ProtoOpts)
  22. when is_integer(NbAcceptors), NbAcceptors > 0 ->
  23. ranch:start_listener(Ref, NbAcceptors,
  24. ranch_tcp, TransOpts, cowboy_protocol, ProtoOpts).
  25. %% @doc Start an HTTPS listener.
  26. -spec start_https(any(), non_neg_integer(), any(), any()) -> {ok, pid()}.
  27. start_https(Ref, NbAcceptors, TransOpts, ProtoOpts)
  28. when is_integer(NbAcceptors), NbAcceptors > 0 ->
  29. ranch:start_listener(Ref, NbAcceptors,
  30. ranch_ssl, TransOpts, cowboy_protocol, ProtoOpts).
  31. %% @doc Stop a listener.
  32. -spec stop_listener(any()) -> ok.
  33. stop_listener(Ref) ->
  34. ranch:stop_listener(Ref).