From f26401af19bddd74ddd1755041372c737a995b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 20 Dec 2012 15:57:54 +0100 Subject: Return {error, badarg} if start_listener got a bad transport module --- src/ranch.erl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/ranch.erl') 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. %% %% Ref 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 Ref. %% -- cgit v1.2.3