aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2015-08-22 14:03:50 +0200
committerLoïc Hoguin <[email protected]>2015-08-22 14:03:50 +0200
commit309f8bacf62efa1bcf6b85bfabc7ae45b6544b79 (patch)
tree42fc68e91e2519b79373da6c7cdebb966bb3b1f5
parentc9da21c7aae3fa1d8032791db8be619668f3357b (diff)
downloadranch-309f8bacf62efa1bcf6b85bfabc7ae45b6544b79.tar.gz
ranch-309f8bacf62efa1bcf6b85bfabc7ae45b6544b79.tar.bz2
ranch-309f8bacf62efa1bcf6b85bfabc7ae45b6544b79.zip
Print a warning when discarding an option on listener startup
-rw-r--r--src/ranch.erl18
-rw-r--r--test/acceptor_SUITE.erl9
2 files changed, 19 insertions, 8 deletions
diff --git a/src/ranch.erl b/src/ranch.erl
index 9f764d3..769447a 100644
--- a/src/ranch.erl
+++ b/src/ranch.erl
@@ -134,8 +134,11 @@ filter_options(UserOptions, AllowedKeys, DefaultOptions) ->
%% 2-tuple options.
filter_user_options([Opt = {Key, _}|Tail], AllowedKeys) ->
case lists:member(Key, AllowedKeys) of
- true -> [Opt|filter_user_options(Tail, AllowedKeys)];
- false -> filter_user_options(Tail, AllowedKeys)
+ true ->
+ [Opt|filter_user_options(Tail, AllowedKeys)];
+ false ->
+ filter_options_warning(Opt),
+ filter_user_options(Tail, AllowedKeys)
end;
%% Special option forms.
filter_user_options([inet|Tail], AllowedKeys) ->
@@ -143,15 +146,16 @@ filter_user_options([inet|Tail], AllowedKeys) ->
filter_user_options([inet6|Tail], AllowedKeys) ->
[inet6|filter_user_options(Tail, AllowedKeys)];
filter_user_options([Opt = {raw, _, _, _}|Tail], AllowedKeys) ->
- case lists:member(raw, AllowedKeys) of
- true -> [Opt|filter_user_options(Tail, AllowedKeys)];
- false -> filter_user_options(Tail, AllowedKeys)
- end;
-filter_user_options([_|Tail], AllowedKeys) ->
+ [Opt|filter_user_options(Tail, AllowedKeys)];
+filter_user_options([Opt|Tail], AllowedKeys) ->
+ filter_options_warning(Opt),
filter_user_options(Tail, AllowedKeys);
filter_user_options([], _) ->
[].
+filter_options_warning(Opt) ->
+ error_logger:warning_msg("Transport option ~p unknown or invalid.~n", [Opt]).
+
merge_options({Key, _} = Option, OptionList) ->
lists:keystore(Key, 1, OptionList, Option);
merge_options(Option, OptionList) ->
diff --git a/test/acceptor_SUITE.erl b/test/acceptor_SUITE.erl
index 93952ca..7eea743 100644
--- a/test/acceptor_SUITE.erl
+++ b/test/acceptor_SUITE.erl
@@ -41,7 +41,8 @@ groups() ->
ssl_active_echo,
ssl_echo
]}, {misc, [
- misc_bad_transport
+ misc_bad_transport,
+ misc_bad_transport_options
]}, {supervisor, [
connection_type_supervisor,
connection_type_supervisor_separate_from_connection,
@@ -61,6 +62,12 @@ misc_bad_transport(_) ->
bad_transport, [], echo_protocol, []),
ok.
+misc_bad_transport_options(_) ->
+ doc("Reject invalid transport modules."),
+ {ok, _} = ranch:start_listener(misc_bad_transport, 1,
+ ranch_tcp, [binary, {packet, 4}, <<"garbage">>, raw, backlog], echo_protocol, []),
+ ok.
+
%% ssl.
ssl_accept_error(_) ->