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?
The second arg to supervisor:start_child/2
is a child specification with the format:
{Id,StartFunction,RestartType,Shutdowntime,ProcessType,Modules}
where
Id
is an identifier of the child which is unique in the supervisor, it can be any datatype.
StartFunction
is a tuple {Module,Function,Args}
which is the call to start the child process.
RestartType
tells the supervisor how this child is to be restart, it can have the values permanent
, transient
or temporary
.
ShutdownTime
is how much the child process is allowed to spend in termination before it is killed.
ProcessType
whether the child is a worker
or supervisor
.
Modules
list of modules implementing the child
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.