diff options
| author | Matthias Radestock <matthias@lshift.net> | 2010-01-27 15:00:43 +0000 |
|---|---|---|
| committer | Matthias Radestock <matthias@lshift.net> | 2010-01-27 15:00:43 +0000 |
| commit | 4691d6a87e77737f9b02b4375be88f290cc07d5a (patch) | |
| tree | 9a628cb02065db124b08109793d6141f3ad37f4f /src | |
| parent | 5ce861e6c5a334013bd937f93abea4671b343816 (diff) | |
| download | rabbitmq-server-git-4691d6a87e77737f9b02b4375be88f290cc07d5a.tar.gz | |
refactor: eliminate code dup
Diffstat (limited to 'src')
| -rw-r--r-- | src/tcp_acceptor.erl | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/tcp_acceptor.erl b/src/tcp_acceptor.erl index 8cdf8d976e..5364acf945 100644 --- a/src/tcp_acceptor.erl +++ b/src/tcp_acceptor.erl @@ -48,14 +48,15 @@ start_link(Callback, LSock) -> %%-------------------------------------------------------------------- init({Callback, LSock}) -> - case prim_inet:async_accept(LSock, -1) of - {ok, Ref} -> {ok, #state{callback=Callback, sock=LSock, ref=Ref}}; - Error -> {stop, {cannot_accept, Error}} - end. + gen_server:cast(self(), accept), + {ok, #state{callback=Callback, sock=LSock}}. handle_call(_Request, _From, State) -> {noreply, State}. +handle_cast(accept, State) -> + accept(State); + handle_cast(_Msg, State) -> {noreply, State}. @@ -83,10 +84,7 @@ handle_info({inet_async, LSock, Ref, {ok, Sock}}, end, %% accept more - case prim_inet:async_accept(LSock, -1) of - {ok, NRef} -> {noreply, State#state{ref=NRef}}; - Error -> {stop, {cannot_accept, Error}, none} - end; + accept(State); handle_info({inet_async, LSock, Ref, {error, closed}}, State=#state{sock=LSock, ref=Ref}) -> %% It would be wrong to attempt to restart the acceptor when we @@ -104,3 +102,9 @@ code_change(_OldVsn, State, _Extra) -> %%-------------------------------------------------------------------- inet_op(F) -> rabbit_misc:throw_on_error(inet_error, F). + +accept(State = #state{sock=LSock}) -> + case prim_inet:async_accept(LSock, -1) of + {ok, Ref} -> {noreply, State#state{ref=Ref}}; + Error -> {stop, {cannot_accept, Error}, State} + end. |
