summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2011-02-02 12:40:13 +0000
committerSimon MacMullen <simon@rabbitmq.com>2011-02-02 12:40:13 +0000
commitb5861c7c239af97813adac731b58049ad66fd9d6 (patch)
tree94905d3dcfb9e0ba35c94dbaa3f9d2d7a61fb496
parentc44c0fb9bb2adcbb9082efdcd18f4444e8a4d203 (diff)
downloadrabbitmq-server-b5861c7c239af97813adac731b58049ad66fd9d6.tar.gz
Return a basic.credit-state after receiving a basic.credit.
-rw-r--r--src/rabbit_channel.erl18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl
index bac106f9..a0624101 100644
--- a/src/rabbit_channel.erl
+++ b/src/rabbit_channel.erl
@@ -1034,6 +1034,19 @@ handle_method(#'basic.credit'{consumer_tag = CTag, credit = Credit,
drain = Drain}, _,
State = #ch{limiter_pid = LimiterPid,
consumer_mapping = Consumers}) ->
+ %% We get Available first because it's likely that as soon as we set
+ %% the credit msgs will get consumed and it'll be out of date. Why do we
+ %% want that? Because at least then it's consistent with the credit value
+ %% we return. And Available is always going to be racy.
+ Available = case dict:find(CTag, Consumers) of
+ {ok, QName} ->
+ case rabbit_amqqueue:with(
+ QName, fun (Q) -> rabbit_amqqueue:stat(Q) end) of
+ {ok, Len, _} -> Len;
+ _ -> -1
+ end;
+ error -> -1
+ end,
LimiterPid1 = case LimiterPid of
undefined -> start_limiter(State);
Other -> Other
@@ -1045,7 +1058,10 @@ handle_method(#'basic.credit'{consumer_tag = CTag, credit = Credit,
stopped -> unlimit_queues(State)
end,
State1 = State#ch{limiter_pid = LimiterPid2},
- {noreply, State1};
+ return_ok(State1, false, #'basic.credit_state'{consumer_tag = CTag,
+ credit = Credit,
+ available = Available,
+ drain = Drain});
%% TODO port this bit ?
%% case consumer_queues(Consumers) of