@@ -125,7 +125,7 @@ heartbeater(Params, Identity) ->
125
125
end )}.
126
126
127
127
heartbeater ({Sock , TimeoutMillisec , StatName , Threshold , Handler } = Params ,
128
- Deb , {StatVal , SameCount } = State ) ->
128
+ Deb , {StatVal0 , SameCount } = State ) ->
129
129
Recurse = fun (State1 ) -> heartbeater (Params , Deb , State1 ) end ,
130
130
System = fun (From , Req ) ->
131
131
sys :handle_system_msg (
@@ -143,23 +143,42 @@ heartbeater({Sock, TimeoutMillisec, StatName, Threshold, Handler} = Params,
143
143
Other ->
144
144
exit ({unexpected_message , Other })
145
145
after TimeoutMillisec ->
146
- case rabbit_net :getstat (Sock , [StatName ]) of
147
- {ok , [{StatName , NewStatVal }]} ->
148
- if NewStatVal =/= StatVal ->
149
- Recurse ({NewStatVal , 0 });
150
- SameCount < Threshold ->
151
- Recurse ({NewStatVal , SameCount + 1 });
152
- true ->
153
- case Handler () of
154
- stop -> ok ;
155
- continue -> Recurse ({NewStatVal , 0 })
156
- end
157
- end ;
158
- {error , einval } ->
159
- % % the socket is dead, most likely because the
160
- % % connection is being shut down -> terminate
161
- ok ;
162
- {error , Reason } ->
163
- exit ({cannot_get_socket_stats , Reason })
164
- end
146
+ OkFun = fun (StatVal1 ) ->
147
+ if StatVal1 =/= StatVal0 ->
148
+ {recurse , {StatVal1 , 0 }};
149
+ SameCount < Threshold ->
150
+ {recurse , {StatVal1 , SameCount + 1 }};
151
+ true ->
152
+ {run_handler , {StatVal1 , 0 }}
153
+ end
154
+ end ,
155
+ SSResult = get_sock_stats (Sock , StatName , OkFun ),
156
+ handle_get_sock_stats (SSResult , Sock , StatName , Recurse , Handler )
157
+ end .
158
+
159
+ handle_get_sock_stats (stop , _Sock , _StatName , _Recurse , _Handler ) ->
160
+ ok ;
161
+ handle_get_sock_stats ({recurse , RecurseArg }, _Sock , _StatName , Recurse , _Handler ) ->
162
+ Recurse (RecurseArg );
163
+ handle_get_sock_stats ({run_handler , {_ , SameCount }}, Sock , StatName , Recurse , Handler ) ->
164
+ case Handler () of
165
+ stop -> ok ;
166
+ continue ->
167
+ OkFun = fun (StatVal ) ->
168
+ {recurse , {StatVal , SameCount }}
169
+ end ,
170
+ SSResult = get_sock_stats (Sock , StatName , OkFun ),
171
+ handle_get_sock_stats (SSResult , Sock , StatName , Recurse , Handler )
172
+ end .
173
+
174
+ get_sock_stats (Sock , StatName , OkFun ) ->
175
+ case rabbit_net :getstat (Sock , [StatName ]) of
176
+ {ok , [{StatName , StatVal }]} ->
177
+ OkFun (StatVal );
178
+ {error , einval } ->
179
+ % % the socket is dead, most likely because the
180
+ % % connection is being shut down -> terminate
181
+ stop ;
182
+ {error , Reason } ->
183
+ exit ({cannot_get_socket_stats , Reason })
165
184
end .
0 commit comments