diff options
| author | Matthias Radestock <matthias@rabbitmq.com> | 2013-12-12 12:34:39 +0000 |
|---|---|---|
| committer | Matthias Radestock <matthias@rabbitmq.com> | 2013-12-12 12:34:39 +0000 |
| commit | c0f3d6ff29d700da173ee17d2487ad8f25a01780 (patch) | |
| tree | c0cef1112ff0fa97bbe6b9192daf00f59c872cfd | |
| parent | ed837f80b9188234d2e1b466b66acc2fb3a55545 (diff) | |
| download | rabbitmq-server-git-c0f3d6ff29d700da173ee17d2487ad8f25a01780.tar.gz | |
refactor: two heads are better than one
| -rw-r--r-- | src/rabbit_reader.erl | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index 45b7ab0999..531ea4ad48 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -603,33 +603,33 @@ payload_snippet(<<Snippet:16/binary, _/binary>>) -> %%-------------------------------------------------------------------------- -create_channel(Channel, State) -> - #v1{sock = Sock, queue_collector = Collector, - channel_sup_sup_pid = ChanSupSup, - channel_count = ChannelCount, - connection = Conn} = State, - #connection{name = Name, - protocol = Protocol, - frame_max = FrameMax, - channel_max = ChannelMax, - user = User, - vhost = VHost, - capabilities = Capabilities} = Conn, - case ChannelMax == 0 orelse ChannelCount < ChannelMax of - true -> {ok, _ChSupPid, {ChPid, AState}} = - rabbit_channel_sup_sup:start_channel( - ChanSupSup, {tcp, Sock, Channel, FrameMax, self(), Name, - Protocol, User, VHost, Capabilities, - Collector}), - MRef = erlang:monitor(process, ChPid), - put({ch_pid, ChPid}, {Channel, MRef}), - {ok, {ChPid, AState}, State#v1{ - channel_count = ChannelCount + 1}}; - false -> {error, rabbit_misc:amqp_error( - not_allowed, "number of channels opened (~w) has " - "reached the negotiated channel_max (~w)", - [ChannelCount, ChannelMax], 'none')} - end. +create_channel(_Channel, + #v1{channel_count = ChannelCount, + connection = #connection{channel_max = ChannelMax}}) + when ChannelMax /= 0 andalso ChannelCount >= ChannelMax -> + {error, rabbit_misc:amqp_error( + not_allowed, "number of channels opened (~w) has reached the " + "negotiated channel_max (~w)", + [ChannelCount, ChannelMax], 'none')}; +create_channel(Channel, + #v1{sock = Sock, + queue_collector = Collector, + channel_sup_sup_pid = ChanSupSup, + channel_count = ChannelCount, + connection = + #connection{name = Name, + protocol = Protocol, + frame_max = FrameMax, + user = User, + vhost = VHost, + capabilities = Capabilities}} = State) -> + {ok, _ChSupPid, {ChPid, AState}} = + rabbit_channel_sup_sup:start_channel( + ChanSupSup, {tcp, Sock, Channel, FrameMax, self(), Name, + Protocol, User, VHost, Capabilities, Collector}), + MRef = erlang:monitor(process, ChPid), + put({ch_pid, ChPid}, {Channel, MRef}), + {ok, {ChPid, AState}, State#v1{channel_count = ChannelCount + 1}}. channel_cleanup(ChPid, State = #v1{channel_count = ChannelCount}) -> case get({ch_pid, ChPid}) of @@ -638,8 +638,7 @@ channel_cleanup(ChPid, State = #v1{channel_count = ChannelCount}) -> erase({channel, Channel}), erase({ch_pid, ChPid}), erlang:demonitor(MRef, [flush]), - {Channel, State#v1{ - channel_count = ChannelCount - 1}} + {Channel, State#v1{channel_count = ChannelCount - 1}} end. all_channels() -> [ChPid || {{ch_pid, ChPid}, _ChannelMRef} <- get()]. |
