summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@lshift.net>2010-01-27 15:00:43 +0000
committerMatthias Radestock <matthias@lshift.net>2010-01-27 15:00:43 +0000
commit438592ea02959529171c33f1d8ac97f8c7be682e (patch)
tree9a628cb02065db124b08109793d6141f3ad37f4f
parent0669ead9e92275c11b20af54f78343d5ccca2421 (diff)
downloadrabbitmq-server-438592ea02959529171c33f1d8ac97f8c7be682e.tar.gz
refactor: eliminate code dup
-rw-r--r--src/tcp_acceptor.erl20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/tcp_acceptor.erl b/src/tcp_acceptor.erl
index 8cdf8d97..5364acf9 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.