summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2010-07-02 17:43:45 +0100
committerSimon MacMullen <simon@rabbitmq.com>2010-07-02 17:43:45 +0100
commit4f4640a08f676cca8605299101265f6fd82277b8 (patch)
treefb18a7801cae433ab834444c42cb91830b6f5e1b
parent98054097344a20ce3a03724295d9e240643efc22 (diff)
downloadrabbitmq-server-4f4640a08f676cca8605299101265f6fd82277b8.tar.gz
Get codegen to build Protocol:version().
-rw-r--r--codegen.py8
-rw-r--r--include/rabbit.hrl4
-rw-r--r--src/rabbit_reader.erl19
3 files changed, 16 insertions, 15 deletions
diff --git a/codegen.py b/codegen.py
index 9596f5b1..9eb6fca2 100644
--- a/codegen.py
+++ b/codegen.py
@@ -316,7 +316,7 @@ def genErl(spec):
printFileHeader()
module = "rabbit_framing_amqp_%d_%d" % (spec.major, spec.minor)
- if spec.revision != '0':
+ if spec.revision != 0:
module = "%s_%d" % (module, spec.revision)
if module == "rabbit_framing_amqp_8_0":
module = "rabbit_framing_amqp_0_8"
@@ -336,6 +336,7 @@ def genErl(spec):
-export([encode_properties/1]).
-export([lookup_amqp_exception/1]).
-export([amqp_exception/1]).
+-export([version/0]).
bitvalue(true) -> 1;
bitvalue(false) -> 0;
@@ -355,6 +356,7 @@ bitvalue(undefined) -> 0.
-spec(encode_properties/1 :: (amqp_method_record()) -> binary()).
-spec(lookup_amqp_exception/1 :: (amqp_exception()) -> {boolean(), amqp_exception_code(), binary()}).
-spec(amqp_exception/1 :: (amqp_exception_code()) -> amqp_exception()).
+-spec(version/0 :: () -> {integer, integer, integer}).
-endif. % use_specs
"""
for m in methods: genLookupMethodName(m)
@@ -396,6 +398,10 @@ bitvalue(undefined) -> 0.
for(c,v,cls) in spec.constants: genAmqpException(c,v,cls)
print "amqp_exception(_Code) -> undefined."
+ version = "{%d, %d, %d}" % (spec.major, spec.minor, spec.revision)
+ if version == '{8, 0, 0}': version = '{0, 8, 0}'
+ print "version() -> %s." % (version)
+
def genHrl(spec):
def erlType(domain):
return erlangTypeMap[spec.resolveDomain(domain)]
diff --git a/include/rabbit.hrl b/include/rabbit.hrl
index 1bb89af9..8c713a50 100644
--- a/include/rabbit.hrl
+++ b/include/rabbit.hrl
@@ -36,8 +36,8 @@
-record(vhost, {virtual_host, dummy}).
--record(connection, {protocol, protocol_name, user, timeout_sec, frame_max,
- vhost, client_properties}).
+-record(connection, {protocol, user, timeout_sec, frame_max, vhost,
+ client_properties}).
-record(content,
{class_id,
diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl
index 72d95c7b..9fbf7ce8 100644
--- a/src/rabbit_reader.erl
+++ b/src/rabbit_reader.erl
@@ -560,14 +560,14 @@ handle_input({frame_payload, Type, Channel, PayloadSize}, PayloadAndMarker, Stat
%% * The server MUST provide a protocol version that is lower than or
%% equal to that requested by the client in the protocol header.
handle_input(handshake, <<"AMQP", 0, 0, 9, 1>>, State) ->
- start_connection({0, 9, 1}, amqp_0_9_1, State);
+ start_connection({0, 9, 1}, rabbit_framing_amqp_0_9_1, State);
handle_input(handshake, <<"AMQP", 1, 1, 0, 9>>, State) ->
- start_connection({0, 9, 0}, amqp_0_9_1, State);
+ start_connection({0, 9, 0}, rabbit_framing_amqp_0_9_1, State);
%% the 0-8 spec, confusingly, defines the version as 8-0
handle_input(handshake, <<"AMQP", 1, 1, 8, 0>>, State) ->
- start_connection({8, 0, 0}, amqp_0_8, State);
+ start_connection({8, 0, 0}, rabbit_framing_amqp_0_8, State);
handle_input(handshake, <<"AMQP", A, B, C, D>>, #v1{sock = Sock}) ->
refuse_connection(Sock, {bad_version, A, B, C, D});
@@ -582,12 +582,8 @@ handle_input(Callback, Data, _State) ->
%% includes a major and minor version number, Luckily 0-9 and 0-9-1
%% are similar enough that clients will be happy with either.
start_connection({ProtocolMajor, ProtocolMinor, _ProtocolRevision},
- ProtocolName,
+ Protocol,
State = #v1{sock = Sock, connection = Connection}) ->
- Protocol = case ProtocolName of
- amqp_0_9_1 -> rabbit_framing_amqp_0_9_1;
- amqp_0_8 -> rabbit_framing_amqp_0_8
- end,
Start = #'connection.start'{ version_major = ProtocolMajor,
version_minor = ProtocolMinor,
server_properties = server_properties(),
@@ -596,8 +592,7 @@ start_connection({ProtocolMajor, ProtocolMinor, _ProtocolRevision},
ok = send_on_channel0(Sock, Start, Protocol),
{State#v1{connection = Connection#connection{
timeout_sec = ?NORMAL_TIMEOUT,
- protocol = Protocol,
- protocol_name = ProtocolName},
+ protocol = Protocol},
connection_state = starting},
frame_header, 7}.
@@ -736,8 +731,8 @@ i(state, #v1{connection_state = S}) ->
S;
i(channels, #v1{}) ->
length(all_channels());
-i(protocol, #v1{connection = #connection{protocol_name = ProtocolName}}) ->
- ProtocolName;
+i(protocol, #v1{connection = #connection{protocol = Protocol}}) ->
+ Protocol:version();
i(user, #v1{connection = #connection{user = #user{username = Username}}}) ->
Username;
i(user, #v1{connection = #connection{user = none}}) ->