erlangnntp

Erlang supervisor:start_child parameters


I'm trying to understand this bit of supervisor code from ErlNNTP and I can't make sense of it even after reading the erlang documentation (Erlang n00b) on start-child (http://www.erlang.org/doc/man/supervisor.html#start_child-2)

start_connection_handler (Socket) -> supervisor:start_child (?MODULE, {Socket, {connection_handler, start_link, [Socket]}, permanent, 10000, worker, [connection_handler]}).

I do't quite get the 'Socket' parameter which I expect to be a SupRef. I'm obviously not parsing the parameter list correctly or understanding the call. Can anyone explain it to me?


Solution

  • The second arg to supervisor:start_child/2 is a child specification with the format:

    {Id,StartFunction,RestartType,Shutdowntime,ProcessType,Modules}
    

    where

    The last two are used when code upgrading.

    So in your case Socket is being use as a identifier. Doing it this way means when you start a handler for a new socket you will get a unique identifier.