Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, you should add these processes to the supervision heirarchy as you want them to be correctly/gracefully shutdown when your application is stopped. (Otherwise you end up leaking connections that will fail as the application infrastructure they depend on been shutdown).</p> <p>You could create a <code>simple_one_for_one</code> strategy supervisor say <code>yourapp_client_sup</code> that has a child spec of <code>{Id, {yourapp_client_connection, start_link_with_socket, []}, Restart, Shutdown, worker, temporary}</code>. The <code>temporary</code> type here is important because there's normally no useful restart strategy for a connection handler - you can't connect out to the client to restart the connection. <code>temporary</code> here will cause the supervisor to report the connection handler exit but otherwise ignore it.</p> <p>The process that does <code>gen_tcp:accept</code> will then create the connection handler process by doing <code>supervisor:start_child(yourapp_client_sup, [Socket,Options,...])</code> rather than <code>yourapp_client_sup:start_link(Socket, Options, ...)</code>. Ensure that the <code>youreapp_client_connection:start_link_with_socket</code> function starts the child via <code>gen_server</code> or <code>proc_lib</code> functions (a requirement of the <code>supervisor</code> module) and that the function transfers control of the socket to the child with <code>gen_tcp:controlling_process</code> otherwise the child won't be able to use the socket.</p> <p>An alternate approach is to create a dummy <code>yourapp_client_sup</code> process that <code>yourclient_connection_handler</code> processes can link to at startup. The <code>yourapp_client_sup</code> process will just exist to propagate <code>EXIT</code> messages from its parent to the connection handler processes. It will need to trap exists and ignore all <code>EXIT</code> messages other than those from its parent. On the whole, I prefer to use the <code>simple_one_for_one</code> supervisor approach.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload