Browse Source

Print a warning when discarding an option on listener startup

Loïc Hoguin 9 years ago
parent
commit
309f8bacf6
2 changed files with 19 additions and 8 deletions
  1. 11 7
      src/ranch.erl
  2. 8 1
      test/acceptor_SUITE.erl

+ 11 - 7
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) ->

+ 8 - 1
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(_) ->