0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Automatically start crypto, public_key and ssl if needed.

Following mochiweb and misultin's example here even though I'm not
too thrilled about starting them and not stopping but it's optional
and the application's author can start/stop them as normal anyway.
This commit is contained in:
Loïc Hoguin 2011-05-24 20:52:19 +02:00
parent 4c4030a792
commit 0720d6b9e3

View file

@ -30,6 +30,7 @@ messages() -> {ssl, ssl_closed, ssl_error}.
| {keyfile, KeyPath::string()} | {password, Password::string()}])
-> {ok, LSocket::ssl:sslsocket()} | {error, Reason::atom()}.
listen(Opts) ->
require([crypto, public_key, ssl]),
{port, Port} = lists:keyfind(port, 1, Opts),
Backlog = proplists:get_value(backlog, Opts, 1024),
{certfile, CertFile} = lists:keyfind(certfile, 1, Opts),
@ -80,6 +81,16 @@ close(Socket) ->
%% Internal.
-spec require(Apps::list(module())) -> ok.
require([]) ->
ok;
require([App|Tail]) ->
case application:start(App) of
ok -> ok;
{error, {already_started, App}} -> ok
end,
require(Tail).
-spec ssl_accept(CSocket::ssl:sslsocket(), Timeout::timeout())
-> {ok, Socket::ssl:sslsocket()} | {error, Reason::closed | timeout | atom()}.
ssl_accept(CSocket, Timeout) ->