[erlang-questions] proper way for a gen_server to self-terminate?

David Budworth dbudworth@REDACTED
Sat Jul 19 01:10:56 CEST 2008


I've been wrestling with creating a proper gen* structure is also a
listening socket server, and I got most everything down except one thing.

i have a supervisor (Sup) to keep track of connection handler (gen_server)
processes.  This supervisor has no children at init time.

in my (non-gen*) acceptor process, I accept a socket, then do:
supervisor:start_child(Sup,{clientspec marked as temporary})

that child process(handler) is then handed the Socket and the acceptor
process gives control to the handler.

if I do supervisor:which_children(Sup) i see it there, and it's doing it's
thing (handle_info({tcp,Socket,<<blah>>}))

now, when the remote side drops the socket, I get the {tcp_closed,Socket}
info message and want to stop my gen_server.

if I return (from handle_info):
{stop,normal,State}

the pid dies, but the supervisor:which_children still shows it as
registered, but the pid is now listed as undefined.

seems like it saw it die, just didn't remove it from the child list.

if I cal supervisor:delete_child(Sup,self()) before returning
{stop,normal,State} from handle_info I get a norpc error.

is there a proper way to have a supervisor with dynamic gen_server children
that suicide?

thanks,

-david
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080718/105bdad6/attachment.htm>


More information about the erlang-questions mailing list