aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ranch.erl14
-rw-r--r--test/acceptor_SUITE.erl15
2 files changed, 25 insertions, 4 deletions
diff --git a/src/ranch.erl b/src/ranch.erl
index 3a79312..6d1d5e8 100644
--- a/src/ranch.erl
+++ b/src/ranch.erl
@@ -47,13 +47,21 @@
%% of connections.
%%
%% <em>Ref</em> can be used to stop the listener later on.
+%%
+%% This function will return `{error, badarg}` if and only if the transport
+%% module given doesn't appear to be correct.
-spec start_listener(any(), non_neg_integer(), module(), any(), module(), any())
- -> {ok, pid()}.
+ -> {ok, pid()} | {error, badarg}.
start_listener(Ref, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts)
when is_integer(NbAcceptors) andalso is_atom(Transport)
andalso is_atom(Protocol) ->
- supervisor:start_child(ranch_sup, child_spec(Ref, NbAcceptors,
- Transport, TransOpts, Protocol, ProtoOpts)).
+ case erlang:function_exported(Transport, name, 0) of
+ false ->
+ {error, badarg};
+ true ->
+ supervisor:start_child(ranch_sup, child_spec(Ref, NbAcceptors,
+ Transport, TransOpts, Protocol, ProtoOpts))
+ end.
%% @doc Stop a listener identified by <em>Ref</em>.
%%
diff --git a/test/acceptor_SUITE.erl b/test/acceptor_SUITE.erl
index 6dd4a9c..0b86a4d 100644
--- a/test/acceptor_SUITE.erl
+++ b/test/acceptor_SUITE.erl
@@ -24,6 +24,9 @@
-export([init_per_group/2]).
-export([end_per_group/2]).
+%% misc.
+-export([misc_bad_transport/1]).
+
%% ssl.
-export([ssl_accept_error/1]).
-export([ssl_active_echo/1]).
@@ -39,7 +42,7 @@
%% ct.
all() ->
- [{group, tcp}, {group, ssl}].
+ [{group, tcp}, {group, ssl}, {group, misc}].
groups() ->
[{tcp, [
@@ -52,6 +55,8 @@ groups() ->
ssl_accept_error,
ssl_active_echo,
ssl_echo
+ ]}, {misc, [
+ misc_bad_transport
]}].
init_per_suite(Config) ->
@@ -78,6 +83,14 @@ end_per_group(ssl, _) ->
end_per_group(_, _) ->
ok.
+%% misc.
+
+misc_bad_transport(_) ->
+ {error, badarg} = ranch:start_listener(misc_bad_transport, 1,
+ bad_transport, [{port, 0}],
+ echo_protocol, []),
+ ok.
+
%% ssl.
ssl_accept_error(Config) ->