diff options
author | Michael Klishin <michael@rabbitmq.com> | 2013-11-26 15:29:02 +0400 |
---|---|---|
committer | Michael Klishin <michael@rabbitmq.com> | 2013-11-26 15:29:02 +0400 |
commit | 58285a490f9ab2c9f3e5e6bf8907607a5296c6d5 (patch) | |
tree | 01f8992e96aa4f8e9e2e6c175c98d6559e565dbf | |
parent | c55fde8f805f56ef61be7501d711c31ed7803dbd (diff) | |
download | rabbitmq-server-58285a490f9ab2c9f3e5e6bf8907607a5296c6d5.tar.gz |
Extract function
-rw-r--r-- | src/rabbit_reader.erl | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index d720ef0e..59b4fec1 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -923,25 +923,34 @@ validate_negotiated_integer_value(Field, ClientValue, ServerValue, Min, State = #v1{sock = Sock, connection = Connection}) -> Protocol = Connection#connection.protocol, if ClientValue /= 0 andalso ClientValue < Min -> - AmqpError = rabbit_misc:amqp_error( - not_allowed, "negotiated ~p = ~w is lower than the minimum allowedvalue (~w)", - [Field, ClientValue, ServerValue], none), - {0, CloseMethod} = - rabbit_binary_generator:map_exception(0, AmqpError, Protocol), - ok = send_on_channel0(Sock, CloseMethod, Protocol), - rabbit_misc:protocol_error(AmqpError); + fail_negotiation(Field, ClientValue, ServerValue, min, State); ServerValue /= 0 andalso ClientValue > ServerValue -> - AmqpError = rabbit_misc:amqp_error( - not_allowed, "negotiated ~p = ~w is greater than the maximum allowed value (~w)", - [Field, ClientValue, ServerValue], none), - {0, CloseMethod} = - rabbit_binary_generator:map_exception(0, AmqpError, Protocol), - ok = send_on_channel0(Sock, CloseMethod, Protocol), - rabbit_misc:protocol_error(AmqpError); + fail_negotiation(Field, ClientValue, ServerValue, max, State); true -> ok end. +fail_negotiation(Field, ClientValue, + ServerValue, MinOrMax, + State = #v1{sock = Sock, connection = Connection}) -> + Protocol = Connection#connection.protocol, + S1 = case MinOrMax of + min -> lower; + max -> greater + end, + S2 = case MinOrMax of + min -> minimum; + max -> maximum + end, + AmqpError = rabbit_misc:amqp_error( + not_allowed, + "negotiated ~p = ~w is ~p than the ~p allowed value (~w)", + [Field, ClientValue, S1, S2, ServerValue], none), + {0, CloseMethod} = + rabbit_binary_generator:map_exception(0, AmqpError, Protocol), + ok = send_on_channel0(Sock, CloseMethod, Protocol), + rabbit_misc:protocol_error(AmqpError). + server_frame_max() -> {ok, FrameMax} = application:get_env(rabbit, frame_max), FrameMax. |