summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2013-01-17 17:45:03 +0000
committerMatthias Radestock <matthias@rabbitmq.com>2013-01-17 17:45:03 +0000
commit672289cefb5532d74bb24924aebd14f4ac7afad8 (patch)
tree5bc04f9d2298edabdfb85212bd9cfb4d662f741a
parent8d6369705ad1ff872fdb1896d05fb28c67e43d8a (diff)
downloadrabbitmq-server-672289cefb5532d74bb24924aebd14f4ac7afad8.tar.gz
refactor: encapsulate rabbit_connection table
-rw-r--r--include/rabbit.hrl2
-rw-r--r--src/rabbit_networking.erl11
-rw-r--r--src/rabbit_reader.erl4
3 files changed, 12 insertions, 5 deletions
diff --git a/include/rabbit.hrl b/include/rabbit.hrl
index 397a3df6..7385b4b3 100644
--- a/include/rabbit.hrl
+++ b/include/rabbit.hrl
@@ -109,5 +109,3 @@
-define(INVALID_HEADERS_KEY, <<"x-invalid-headers">>).
-define(ROUTING_HEADERS, [<<"CC">>, <<"BCC">>]).
-define(DELETED_HEADER, <<"BCC">>).
-
--define(CONNECTION_TABLE, rabbit_connection).
diff --git a/src/rabbit_networking.erl b/src/rabbit_networking.erl
index e864140d..ee430fb4 100644
--- a/src/rabbit_networking.erl
+++ b/src/rabbit_networking.erl
@@ -18,7 +18,8 @@
-export([boot/0, start/0, start_tcp_listener/1, start_ssl_listener/2,
stop_tcp_listener/1, on_node_down/1, active_listeners/0,
- node_listeners/1, connections/0, connection_info_keys/0,
+ node_listeners/1, register_connection/1, unregister_connection/1,
+ connections/0, connection_info_keys/0,
connection_info/1, connection_info/2,
connection_info_all/0, connection_info_all/1,
close_connection/2, force_connection_event_refresh/0, tcp_host/1]).
@@ -40,6 +41,8 @@
-define(FIRST_TEST_BIND_PORT, 10000).
+-define(CONNECTION_TABLE, rabbit_connection).
+
%%----------------------------------------------------------------------------
-ifdef(use_specs).
@@ -65,6 +68,8 @@
-spec(stop_tcp_listener/1 :: (listener_config()) -> 'ok').
-spec(active_listeners/0 :: () -> [rabbit_types:listener()]).
-spec(node_listeners/1 :: (node()) -> [rabbit_types:listener()]).
+-spec(register_connection/1 :: (pid()) -> ok).
+-spec(unregister_connection/1 :: (pid()) -> ok).
-spec(connections/0 :: () -> [rabbit_types:connection()]).
-spec(connections_local/0 :: () -> [rabbit_types:connection()]).
-spec(connection_info_keys/0 :: () -> rabbit_types:info_keys()).
@@ -295,6 +300,10 @@ start_client(Sock) ->
start_ssl_client(SslOpts, Sock) ->
start_client(Sock, ssl_transform_fun(SslOpts)).
+register_connection(Pid) -> ets:insert(?CONNECTION_TABLE, {Pid}), ok.
+
+unregister_connection(Pid) -> ets:delete(?CONNECTION_TABLE, Pid), ok.
+
connections() ->
rabbit_misc:append_rpc_all_nodes(rabbit_mnesia:cluster_nodes(running),
rabbit_networking, connections_local, []).
diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl
index f5ddf1b0..13459350 100644
--- a/src/rabbit_reader.erl
+++ b/src/rabbit_reader.erl
@@ -266,7 +266,7 @@ start_connection(Parent, ConnSupPid, Collector, StartHeartbeatFun, Deb,
%% accounting as accurate as possible we ought to close the
%% socket w/o delay before termination.
rabbit_net:fast_close(ClientSock),
- ets:delete(?CONNECTION_TABLE, self()),
+ rabbit_networking:unregister_connection(self()),
rabbit_event:notify(connection_closed, [{pid, self()}])
end,
done.
@@ -722,7 +722,7 @@ handle_input(Callback, Data, _State) ->
start_connection({ProtocolMajor, ProtocolMinor, _ProtocolRevision},
Protocol,
State = #v1{sock = Sock, connection = Connection}) ->
- ets:insert(?CONNECTION_TABLE, {self()}),
+ rabbit_networking:register_connection(self()),
Start = #'connection.start'{
version_major = ProtocolMajor,
version_minor = ProtocolMinor,