[erlang-questions] Adding simple process to supervisor?

Serge Aleynikov saleyn@REDACTED
Fri Oct 10 14:19:51 CEST 2008


If you need a completely non-blocking solution, you can read this article:
http://www.trapexit.org/Building_a_Non-blocking_TCP_server_using_OTP_principles

Serge

Bengt Kleberg wrote:
> Greetings,
> 
> After suggestions from the list I have have tried the "proc_lib creates
> special process" method. It meant using proc_lib:start_link/3, calling
> proc_lib:init_ack/2, adding receive of system messages (2 lines) and 2
> exported call-back functions (1 line each). That was acceptable
> complications too me since I keep all the restarting in the supervisor.
> Note that I think using your method would have been fewer lines.
> 
> However, the process blocks in gen_tcp:accept/1, thus missing any system
> messages during this time. Is there a way around that?
> 
> 
> bengt
> 
> On Thu, 2008-10-09 at 21:43 +0100, Oscar Hellström wrote:
>> Hi Bengt,
>>
>> What I usually do is just to spawn a reader process from the gen_server and link to it. Then depending on if the gen_server should die with errors in the reader process or not I sometimes traps exits in the gen_server. Most of the time you want to restart the gen_server to open a new socket if the reader dies anyway.  IMHO, there are too many issues with trying to get a process that does blocking calls to exist under a supervisor and this kind of process is typically very simple (read small room for errors) as well. Another approach is to use proc_lib to create a "special process" which uses {active, once} for the socket, to get away from doing blocking calls.
>>
>> ----- Original Message -----
>> From: "Bengt Kleberg" <bengt.kleberg@REDACTED>
>> To: "erlang-questions" <erlang-questions@REDACTED>
>> Sent: Thursday, 9 October, 2008 12:03:27 AM GMT -08:00 US/Canada Pacific
>> Subject: [erlang-questions] Adding simple process to supervisor?
>>
>> Greetings,
>>
>> I have a gen_server which is supervised according to OTP rules. Now I  
>> want to add a simple process that will read from a TCP port and send  
>> the incoming data to the gen_server. I could spawn_link this process  
>> from the gen_server and restart it if it dies. However, since I have a  
>> supervisor it seems more logical to just add the process there, as a  
>> rest_for_one.
>>
>>
>> There is the alternative of using a supervisor_bridge, but that seems  
>> more complex than using the gen_server. It seems as if I just design  
>> my process according to the OTP rules I will not need to use a  
>> supervisor_bridge. What are those rules? The only suggestions I have
>> found are:
>> 1 Module:start_link/1 => {ok, Pid}
>> 2 Module:terminate/2 => ok
>>
>>
>> The child specification returned by the init/1 call-back in a  
>> supervisor mentions the value for Modules if we have a gen_server,  
>> gen_fsm or gen_event. What could be used for a simple process?
>>
>>
>> But how do I add a simple process to the supervisor? It seems overkill
>> to masquerade it as a get_fsm or similar. Since it is not called from
>> erlang it is not a gen_server. Since it does not have state it is not a
>> gen_fsm. No events are handled.
>>
>>
>> bengt
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 




More information about the erlang-questions mailing list