Guest User

Untitled

a guest
Oct 20th, 2017
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.76 KB | None | 0 0
  1. -module(simple_tcp_sup).
  2.  
  3. -behaviour(supervisor).
  4.  
  5. -export([start_link/0,
  6.          start_child/1
  7.         ]).
  8.  
  9. -export([init/1]).
  10.  
  11. -define(SERVER, ?MODULE).
  12.  
  13. start_link() ->
  14.     supervisor:start_link({local, ?SERVER}, ?MODULE, []).
  15.  
  16. start_child({socket, Socket}) ->
  17.     io:fwrite("Spawning child with socket...~n"),
  18.     supervisor:start_child(?SERVER, [{socket, Socket}]);
  19.  
  20. start_child({port, Port}) ->
  21.     io:fwrite("Spawning child with port...~n"),
  22.     supervisor:start_child(?SERVER, [{port, Port}]).
  23.  
  24. init([]) ->
  25.     Element = {simple_tcp, {simple_tcp, start_link, []},
  26.                temporary, brutal_kill, worker, [simple_tcp]},
  27.     Children = [Element],
  28.     RestartStrategy = {simple_one_for_one, 0, 1},
  29.     {ok, {RestartStrategy, Children}}.
Add Comment
Please, Sign In to add comment