[erlang-questions] EPmail-0.1 released

Jachym Holecek freza@REDACTED
Sat Jan 29 15:14:02 CET 2011


# Alexander Kuleshov 2011-01-29:
> Thank you Johan for help.
> 
> I try to supervisor start_child gen_gsm:
> 
> accept(Socket) ->
>    case gen_tcp:accept(Socket) of
>        {ok, Sock} ->
              Pid = popd_sup:add_socket(Sock),
	      ok = gen_tcp:controlling_process(Sock, Pid),
	      popd_fsm:kick(Pid),
	      accept(Socket);
	  [...]

Where popd_sup exports:

    add_socket(Sock) ->
        Child = {Sock, {popd_fsm, start_link, [Sock, [], []]},
                 temporary, 2000, worker, [popd_fsm]},
        {ok, Pid} = supervisor:start_child(popd_sup, Child),
	Pid.

Note unique child Id this time and more suitable restart strategy. I'd keep
the supervisor one_for_one, but that's just because I don't like
simple_one_for_one much for no clear reason.

And popd_fsm has something like:

    kick(Pid) ->
        catch gen_fsm:send_event(Pid, kick),
        ok.

    [...]

    initial(kick, #state{sock = Sock} = State) ->
	ok = inet:setopts(Sock, [{active, once}]),
        ok = gen_tcp:send(Sock, "+OK POP3 server ready \r\n"),
	{next_state, whatever, State};

Besides fixing bugs that others already pointed out, I suppose my point is
to encapsulate functionality into modules that actually provide it instead
of scattering "lowlevel" calls (supervisor:start_child/X, gen_server:call/X,
gen_fsm:send_event/X and such) all around the place.

Anyway, this is just a quick sketch written without much thought...

HTH,
	-- Jachym


More information about the erlang-questions mailing list