diff options
author | Matthew Sackman <matthew@rabbitmq.com> | 2010-08-17 14:05:52 +0100 |
---|---|---|
committer | Matthew Sackman <matthew@rabbitmq.com> | 2010-08-17 14:05:52 +0100 |
commit | e0f9f9e39d479f2635ea0af983455388c57a9039 (patch) | |
tree | cde9a94cd0c5e35883094d334878db211eecd5de | |
parent | 73f9b32cce3c81409fa41a810b2dc316a426a042 (diff) | |
download | rabbitmq-server-bug23135.tar.gz |
obtain_and_release_on_death => obtain, and minor refactor of tcp acceptorbug23135
-rw-r--r-- | src/file_handle_cache.erl | 24 | ||||
-rw-r--r-- | src/tcp_acceptor.erl | 6 |
2 files changed, 14 insertions, 16 deletions
diff --git a/src/file_handle_cache.erl b/src/file_handle_cache.erl index ddf8fe38..fe4bdc03 100644 --- a/src/file_handle_cache.erl +++ b/src/file_handle_cache.erl @@ -130,7 +130,7 @@ -export([open/3, close/1, read/2, append/2, sync/1, position/2, truncate/1, last_sync_offset/1, current_virtual_offset/1, current_raw_offset/1, flush/1, copy/3, set_maximum_since_use/1, delete/1, clear/1]). --export([obtain_and_release_on_death/1]). +-export([obtain/1]). -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). @@ -222,7 +222,7 @@ -spec(set_maximum_since_use/1 :: (non_neg_integer()) -> 'ok'). -spec(delete/1 :: (ref()) -> ok_or_error()). -spec(clear/1 :: (ref()) -> ok_or_error()). --spec(obtain_and_release_on_death/1 :: (pid()) -> 'ok'). +-spec(obtain/1 :: (pid()) -> 'ok'). -endif. @@ -444,8 +444,8 @@ set_maximum_since_use(MaximumAge) -> true -> ok end. -obtain_and_release_on_death(Pid) -> - gen_server:call(?SERVER, {obtain_and_release_on_death, Pid}, infinity). +obtain(Pid) -> + gen_server:call(?SERVER, {obtain, Pid}, infinity). %%---------------------------------------------------------------------------- %% Internal functions @@ -741,19 +741,17 @@ init([]) -> client_mrefs = dict:new(), timer_ref = undefined }}. -handle_call({obtain_and_release_on_death, Pid}, From, - State = #fhc_state { obtain_limit = Limit, - obtain_count = Count, - obtain_pending = Pending, - elders = Elders }) +handle_call({obtain, Pid}, From, State = #fhc_state { obtain_limit = Limit, + obtain_count = Count, + obtain_pending = Pending, + elders = Elders }) when Limit =/= infinity andalso Count >= Limit -> {noreply, State #fhc_state { obtain_pending = [{obtain, Pid, From} | Pending], elders = dict:erase(Pid, Elders) }}; -handle_call({obtain_and_release_on_death, Pid}, From, - State = #fhc_state { obtain_count = Count, - obtain_pending = Pending, - elders = Elders }) -> +handle_call({obtain, Pid}, From, State = #fhc_state { obtain_count = Count, + obtain_pending = Pending, + elders = Elders }) -> case maybe_reduce(State #fhc_state { obtain_count = Count + 1 }) of {true, State1} -> {noreply, State1 #fhc_state { diff --git a/src/tcp_acceptor.erl b/src/tcp_acceptor.erl index 88fd2fd4..11ce6fc5 100644 --- a/src/tcp_acceptor.erl +++ b/src/tcp_acceptor.erl @@ -43,12 +43,11 @@ %%-------------------------------------------------------------------- start_link(Callback, LSock) -> - gen_server:start_link(?MODULE, {Callback, LSock}, [{timeout, infinity}]). + gen_server:start_link(?MODULE, {Callback, LSock}, []). %%-------------------------------------------------------------------- init({Callback, LSock}) -> - ok = file_handle_cache:obtain_and_release_on_death(self()), gen_server:cast(self(), accept), {ok, #state{callback=Callback, sock=LSock}}. @@ -56,6 +55,7 @@ handle_call(_Request, _From, State) -> {noreply, State}. handle_cast(accept, State) -> + ok = file_handle_cache:obtain(self()), accept(State); handle_cast(_Msg, State) -> @@ -84,7 +84,7 @@ handle_info({inet_async, LSock, Ref, {ok, Sock}}, %% is drained. gen_event:which_handlers(error_logger), %% handle - file_handle_cache:obtain_and_release_on_death(apply(M, F, A ++ [Sock])) + file_handle_cache:obtain(apply(M, F, A ++ [Sock])) catch {inet_error, Reason} -> gen_tcp:close(Sock), error_logger:error_msg("unable to accept TCP connection: ~p~n", |