diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2011-02-02 12:40:13 +0000 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2011-02-02 12:40:13 +0000 |
| commit | a8f202f13a00cd8819bd4a0bdc6a69420ad67389 (patch) | |
| tree | 94905d3dcfb9e0ba35c94dbaa3f9d2d7a61fb496 /src | |
| parent | 6178c2747d7b2a0a747f1d4e58a917dd7afeb12f (diff) | |
| download | rabbitmq-server-git-a8f202f13a00cd8819bd4a0bdc6a69420ad67389.tar.gz | |
Return a basic.credit-state after receiving a basic.credit.
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_channel.erl | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index bac106f993..a06241017c 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 |
