gen_event and multiple handler ``instances''

Dustin Sallings <>
Mon May 3 23:11:46 CEST 2004


	I'm making my away around the OTP modules (it seems that I need just 
about every one of them for a simple application I'm writing) and I've 
got a question regarding gen_event.

	It seems that gen_event doesn't want you to have multiple handlers 
from the same module registered.  I was hoping for something more like 
NSNotificationCenter (if you're familiar with Objective C) where I 
could register something more like a process.  Does something exist 
that is more suited to my needs?

	Essentially, my app consists of a multicast listener that watches for 
environmental data updates on my network and transforms those into 
events.  I have another process that is a TCP listener that accepts 
connections and sends the updates across it, essentially transforming 
the local multicast to TCP unicast.  I thought I could get away with 
the following:

init([Socket|Args]) ->
     error_logger:info_msg("Starting event handler with:  ~p~n", 
[Socket]),
     {ok, Socket}.


	This does seem to do what I want, but it's unclear to me how I'd go 
about deleting the handler when the socket disconnects:

3> gen_event:which_handlers(temp_listener_events).
[lemp_handler,lemp_handler]

	Currently, I just let the handler crash and get a giant error message, 
but it seems like there would be a better way.  Any ideas?

-- 
Dustin Sallings




More information about the erlang-questions mailing list