summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Harrop <rob@rabbitmq.com>2010-11-10 19:27:14 +0000
committerRob Harrop <rob@rabbitmq.com>2010-11-10 19:27:14 +0000
commit44f8315a2c86e82c161a7ea022df1dcf33516f4a (patch)
tree5e478664a8a5c97e431e75371b8645a5f0b3860a
parent28409088bda290347a25a61a47aaceca156c3316 (diff)
downloadrabbitmq-server-bug23447.tar.gz
Backout heartbeat changes on this branch. All worked moved to bug23484bug23447
-rw-r--r--src/rabbit_connection_sup.erl13
-rw-r--r--src/rabbit_heartbeat.erl14
2 files changed, 9 insertions, 18 deletions
diff --git a/src/rabbit_connection_sup.erl b/src/rabbit_connection_sup.erl
index 184b0245..b3821d3b 100644
--- a/src/rabbit_connection_sup.erl
+++ b/src/rabbit_connection_sup.erl
@@ -83,26 +83,17 @@ start_heartbeat_fun(SupPid) ->
none;
(Sock, TimeoutSec) ->
Parent = self(),
- SendFun =
- fun() ->
- Frame = rabbit_binary_generator:build_heartbeat_frame(),
- catch rabbit_net:send(Sock, Frame)
- end,
- TimeoutFun =
- fun() ->
- Parent ! timeout
- end,
{ok, Sender} =
supervisor2:start_child(
SupPid, {heartbeat_sender,
{rabbit_heartbeat, start_heartbeat_sender,
- [Sock, TimeoutSec, SendFun]},
+ [Parent, Sock, TimeoutSec]},
transient, ?MAX_WAIT, worker, [rabbit_heartbeat]}),
{ok, Receiver} =
supervisor2:start_child(
SupPid, {heartbeat_receiver,
{rabbit_heartbeat, start_heartbeat_receiver,
- [Sock, TimeoutSec, TimeoutFun]},
+ [Parent, Sock, TimeoutSec]},
transient, ?MAX_WAIT, worker, [rabbit_heartbeat]}),
{Sender, Receiver}
end.
diff --git a/src/rabbit_heartbeat.erl b/src/rabbit_heartbeat.erl
index 8188f381..a9945af1 100644
--- a/src/rabbit_heartbeat.erl
+++ b/src/rabbit_heartbeat.erl
@@ -43,13 +43,12 @@
-export_type([heartbeaters/0]).
-type(heartbeaters() :: rabbit_types:maybe({pid(), pid()})).
--type(callback_fun() :: fun (() -> any())).
-spec(start_heartbeat_sender/3 ::
- (rabbit_net:socket(), non_neg_integer(), callback_fun()) ->
+ (pid(), rabbit_net:socket(), non_neg_integer()) ->
rabbit_types:ok(pid())).
-spec(start_heartbeat_receiver/3 ::
- (rabbit_net:socket(), non_neg_integer(), callback_fun()) ->
+ (pid(), rabbit_net:socket(), non_neg_integer()) ->
rabbit_types:ok(pid())).
-spec(pause_monitor/1 :: (heartbeaters()) -> 'ok').
@@ -59,23 +58,24 @@
%%----------------------------------------------------------------------------
-start_heartbeat_sender(Sock, TimeoutSec, SendFun) ->
+start_heartbeat_sender(_Parent, Sock, TimeoutSec) ->
%% the 'div 2' is there so that we don't end up waiting for nearly
%% 2 * TimeoutSec before sending a heartbeat in the boundary case
%% where the last message was sent just after a heartbeat.
heartbeater(
{Sock, TimeoutSec * 1000 div 2, send_oct, 0,
fun () ->
- SendFun(),
+ catch rabbit_net:send(
+ Sock, rabbit_binary_generator:build_heartbeat_frame()),
continue
end}).
-start_heartbeat_receiver(Sock, TimeoutSec, TimeoutFun) ->
+start_heartbeat_receiver(Parent, Sock, TimeoutSec) ->
%% we check for incoming data every interval, and time out after
%% two checks with no change. As a result we will time out between
%% 2 and 3 intervals after the last data has been received.
heartbeater({Sock, TimeoutSec * 1000, recv_oct, 1, fun () ->
- TimeoutFun(),
+ Parent ! timeout,
stop
end}).