Skip to content

Commit

Permalink
Revert "worker processes"
Browse files Browse the repository at this point in the history
This reverts commit e7aa80f.
  • Loading branch information
etrepum committed Jul 24, 2010
1 parent a1845fd commit e43e31f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 34 deletions.
34 changes: 6 additions & 28 deletions src/mochiweb_acceptor.erl
Expand Up @@ -9,52 +9,30 @@
-include("internal.hrl").

-export([start_link/3, init/3]).
-export([worker/3]).

start_link(Server, Listen, Loop) ->
proc_lib:spawn_link(?MODULE, init, [Server, Listen, Loop]).

init(Server, Listen, Loop) ->
T1 = now(),
case catch mochiweb_socket:accept(Listen) of
{ok, Socket} ->
spawn_call_loop(Loop, Socket);
gen_server:cast(Server, {accepted, self(), timer:now_diff(now(), T1)}),
call_loop(Loop, Socket);
{error, closed} ->
ok;
exit(normal);
{error, timeout} ->
ok;
exit(normal);
{error, esslaccept} ->
ok;
exit(normal);
Other ->
error_logger:error_report(
[{application, mochiweb},
"Accept failed error",
lists:flatten(io_lib:format("~p", [Other]))]),
exit({error, accept_failed})
end,
init(Server, Listen, Loop).

spawn_call_loop(Loop, Socket) ->
Pid = proc_lib:spawn(?MODULE, worker, [self(), Loop, Socket]),
case mochiweb_socket:controlling_process(Socket, Pid) of
ok ->
Pid ! self();
Other ->
error_logger:error_report(
[{application, mochiweb},
"Accept failure while setting controlling process",
lists:flatten(io_lib:format("~p", [Other]))]),
exit({error, accept_worker_failed})
end.

worker(Parent, Loop, Socket) ->
receive
Parent ->
ok
after 60000 ->
exit(normal)
end,
call_loop(Loop, Socket).

call_loop({M, F}, Socket) ->
M:F(Socket);
call_loop({M, F, A}, Socket) ->
Expand Down
7 changes: 1 addition & 6 deletions src/mochiweb_socket.erl
Expand Up @@ -5,7 +5,7 @@
-module(mochiweb_socket).

-export([listen/4, accept/1, recv/3, send/2, close/1, port/1, peername/1,
setopts/2, type/1, controlling_process/2]).
setopts/2, type/1]).

-define(ACCEPT_TIMEOUT, 2000).

Expand Down Expand Up @@ -77,11 +77,6 @@ setopts({ssl, Socket}, Opts) ->
setopts(Socket, Opts) ->
inet:setopts(Socket, Opts).

controlling_process({ssl, Socket}, Pid) ->
ssl:controlling_process(Socket, Pid);
controlling_process(Socket, Pid) ->
gen_tcp:controlling_process(Socket, Pid).

type({ssl, _}) ->
ssl;
type(_) ->
Expand Down

0 comments on commit e43e31f

Please sign in to comment.