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 | cefce1d5dc3821943673fbbdbc98ca26adfe7437 (patch) | |
| tree | 01f8992e96aa4f8e9e2e6c175c98d6559e565dbf /src | |
| parent | 50f22c3489dd4a3a28b666b69351852273059d60 (diff) | |
| download | rabbitmq-server-git-cefce1d5dc3821943673fbbdbc98ca26adfe7437.tar.gz | |
Extract function
Diffstat (limited to 'src')
| -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 d720ef0e16..59b4fec182 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. |
