summaryrefslogtreecommitdiff
path: root/src/rabbit_reader.erl
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2012-10-19 14:58:47 +0100
committerSimon MacMullen <simon@rabbitmq.com>2012-10-19 14:58:47 +0100
commitad8f1a01c955ff4a4a07878d4cd97512c7f0c115 (patch)
tree74c80c064d5b59c19e34ab22b94472a3babc799d /src/rabbit_reader.erl
parentd659f7cc57c8595f5c25aa36d1395850d4a44c6a (diff)
downloadrabbitmq-server-ad8f1a01c955ff4a4a07878d4cd97512c7f0c115.tar.gz
Symmetry. Link to the spawned process. Remove i/2 grossness.
Diffstat (limited to 'src/rabbit_reader.erl')
-rw-r--r--src/rabbit_reader.erl30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl
index d3e8d4f6..3cffd1ae 100644
--- a/src/rabbit_reader.erl
+++ b/src/rabbit_reader.erl
@@ -39,11 +39,11 @@
connection_state, queue_collector, heartbeater, stats_timer,
channel_sup_sup_pid, start_heartbeat_fun, buf, buf_len,
auth_mechanism, auth_state, conserve_resources,
- last_blocked_by, last_blocked_at, peer_host}).
+ last_blocked_by, last_blocked_at, host, peer_host}).
-define(STATISTICS_KEYS, [pid, recv_oct, recv_cnt, send_oct, send_cnt,
send_pend, state, last_blocked_by, last_blocked_age,
- channels, peer_host]).
+ channels, host, peer_host]).
-define(CREATION_EVENT_KEYS, [pid, name, address, port, peer_address, peer_port,
ssl, peer_cert_subject, peer_cert_issuer,
@@ -227,10 +227,7 @@ start_connection(Parent, ChannelSupSupPid, Collector, StartHeartbeatFun, Deb,
last_blocked_at = never,
peer_host = unknown},
Self = self(),
- spawn(fun() ->
- Res = rabbit_networking:tcp_host(i(peer_address, State)),
- Self ! {rdns, Res}
- end),
+ spawn_link(fun() -> do_reverse_dns(ClientSock, Self) end),
try
ok = inet_op(fun () -> rabbit_net:tune_buffer_size(ClientSock) end),
recvloop(Deb, switch_callback(rabbit_event:init_stats_timer(
@@ -256,6 +253,18 @@ start_connection(Parent, ChannelSupSupPid, Collector, StartHeartbeatFun, Deb,
end,
done.
+do_reverse_dns(Sock, Reader) ->
+ Host = do_reverse_dns0(Sock, fun rabbit_net:sockname/1),
+ PeerHost = do_reverse_dns0(Sock, fun rabbit_net:peername/1),
+ unlink(Reader),
+ Reader ! {rdns, Host, PeerHost}.
+
+do_reverse_dns0(Sock, Fun) ->
+ case Fun(Sock) of
+ {ok, {IP, _Port}} -> rabbit_networking:tcp_host(IP);
+ _ -> undefined
+ end.
+
recvloop(Deb, State = #v1{pending_recv = true}) ->
mainloop(Deb, State);
recvloop(Deb, State = #v1{connection_state = blocked}) ->
@@ -354,8 +363,9 @@ handle_other({system, From, Request}, Deb, State = #v1{parent = Parent}) ->
handle_other({bump_credit, Msg}, Deb, State) ->
credit_flow:handle_bump_msg(Msg),
recvloop(Deb, control_throttle(State));
-handle_other({rdns, Host}, Deb, State) ->
- mainloop(Deb, State#v1{peer_host = list_to_binary(Host)});
+handle_other({rdns, Host, PeerHost}, Deb, State) ->
+ mainloop(Deb, State#v1{host = list_to_binary(Host),
+ peer_host = list_to_binary(PeerHost)});
handle_other(Other, _Deb, _State) ->
%% internal error -> something worth dying for
exit({unexpected_message, Other}).
@@ -883,8 +893,10 @@ i(pid, #v1{}) ->
self();
i(name, #v1{sock = Sock}) ->
list_to_binary(name(Sock));
-i(peer_host, #v1{peer_host = Host}) ->
+i(host, #v1{host = Host}) ->
Host;
+i(peer_host, #v1{peer_host = PeerHost}) ->
+ PeerHost;
i(address, #v1{sock = Sock}) ->
socket_info(fun rabbit_net:sockname/1, fun ({A, _}) -> A end, Sock);
i(port, #v1{sock = Sock}) ->