From 309f8bacf62efa1bcf6b85bfabc7ae45b6544b79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sat, 22 Aug 2015 14:03:50 +0200 Subject: Print a warning when discarding an option on listener startup --- src/ranch.erl | 18 +++++++++++------- test/acceptor_SUITE.erl | 9 ++++++++- 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(_) -> -- cgit v1.2.3