passive mode sockets and supervisors

paweł kamiński kamiseq@REDACTED
Fri Jun 19 18:19:25 CEST 2009

maybe I will begin from problem Im receiving. when I kill exit(PID,
is_good_as_dead) a process that talks to socket and restart it by supervisor
then Im getting
=ERROR REPORT==== 19-Jun-2009::17:00:01 ===
Error in process <0.57.0> with exit value: {{case_clause,*{error,ealready}*

ok so now I try to describe my app in more details :)
I wrote a small app where I have a listener process that owns a main socket
and accepts incoming connections from clients.
it then spawns by calling supervisor (simple_one_for_one)
start_child(SupPid, [CliSocket]) new proxy.
a proxy is a *pair of processes *one that *only *receives data from client
and pass it to the system and one that *only *sends data from system to
it works -*maybe some ideas how to improve model to work even better* and
maybe it works on a small scale with small amount of data being send and
processes that are created. - but I can spawn many proxies and talk with all
clients and so on.

the main socket is set to passive mode and all accepted sockets are passive
as well, I dont change owner of the socket and leave it as it was to
listening process.

ok. when Im killing a proxy (that is under supervisor controll) I have
message from gen_tcp:recv() Error in process <0.57.0> with exit value:
1)Why is that so? when I create only process that only sends to a proxy (the
other is commented) I can kill process and supervisor is able to respawn it
without problem.

2)what is all about gen_tcp:controlling_process, can somebody point me to
some better explanation of "all side effects" of using or not using that
All I could find about sockets is that when one process is accepting the
socket becames owner of the socket and links to it and can receive msges
from socket when in active mode.
so all I understand is

   - when this process dies the socket is closed.
   - it doesnt really say anything about being in passive mode, should
   process be an owner of the process if it wants to recv() from the socket??
   can one process be owner of more then one socket. *my app gave me an
   impression that one process can be an owner and other can read from a
   socket, but maybe I got luck so please can somebody explain it to me!*
   - another thing is if the process that reads from socket must be the
   owner of it how to make a fault tolerant app, assuming that only process did
   something wrong and socket is perfectly fine so I want only to restart
   process and inject the existing socket into it and continue talking to a
   client. but when the killed process was the owner then I cant assign new
   process to a existing socket and all I can do is close and open a connection
   with client again.

I hope someone understood what I am asking for :)

take care

Paweł Kamiński


More information about the erlang-questions mailing list