<div>You could call event_init immediately after you fork in a child to get a fresh libevent instance. event_init returns a pointer to the event_base for the new instance which you must store and associate with all future events you plan to register. When registering a new event you must first set the appropriate base with event_base_set. The last time I looked, the most recently created event_base is assumed when a specific base is not provided, but I would not rely on that behavior.
</div>
<div> </div>
<div>This approach is based upon my understanding of how libevent works internally, I've never actually used it with epoll on Linux, only devpoll on Solaris which is similar. If it works, your children will inherit the parent's epoll fd but just ignore it. Not sure if that's the behavior you'd like. I'm also a bit curious why you're using libevent in the first place if the architecture of your app is such that it forks for each client. libevent, and event based programming in general, allow you to service multiple clients from the same process quite easily.
</div>
<div> </div>
<div>Andrew<br> </div>
<div><span class="gmail_quote">On 1/22/07, <b class="gmail_sendername">Wilmer van der Gaast</b> <<a href="mailto:wilmer@gaast.net">wilmer@gaast.net</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hello,<br><br>I'm getting very strange behaviour from libevent (when using it with<br>epoll()). My program (BitlBee in ForkDaemon mode) has a master process
<br>which accepts clients and creates a new child process for every<br>connection. When using select() or poll() for event handling, this works<br>perfectly. However, when using epoll() (which is the whole reason I<br>started using libevent, GLib can do event handling with poll()/select()
<br>already) things go wrong once there's more than one client.<br><br>With only one client everything works perfectly, but once there's<br>another one, process 1 seems to get the other process' event<br>notifications. (Process 2 does get the notifications too, BTW.) Process
<br>1 then tries to read from the socket, gets EAGAIN and panics because it<br>obviously doesn't expect to get such an error in a "there's data, read<br>it" event handler.<br><br>Most likely this behaviour comes from the fact that all processes share
<br>one epoll fd, which is hardly ever a good idea. See this post:<br><br><a href="http://www.ussg.iu.edu/hypermail/linux/kernel/0403.0/0300.html">http://www.ussg.iu.edu/hypermail/linux/kernel/0403.0/0300.html</a><br><br>
So now I'm wondering, how do I make sure every process gets its own<br>epfd? I found epoll_base_free(), but it's probably not what I'm looking<br>for, because of this line:<br><br>assert(TAILQ_EMPTY(&base->eventqueue));
<br><br>This means that I have to remove all event handlers to make this<br>function call successful, right? I really shouldn't do that, because<br>most likely doing that will remove the event handler in the parent<br>
process too!!! (See the rest of the thread above.)<br><br>So, does anybody know what to do to make this work properly?<br><br><br>Wilmer van der Gaast.<br><br>--<br>+-------- .''`. - -- ---+ + - -- --- ---- ----- ------+
<br>| wilmer : :' : <a href="http://gaast.net">gaast.net</a> | | OSS Programmer <a href="http://www.bitlbee.org">www.bitlbee.org</a> |<br>| lintux `. `~' <a href="http://debian.org">debian.org</a> | | Full-time geek
<a href="http://wilmer.gaast.net">wilmer.gaast.net</a> |<br>+--- -- - ` ---------------+ +------ ----- ---- --- -- - +<br><br><br><br><br><br>_______________________________________________<br>Libevent-users mailing list
<br><a href="mailto:Libevent-users@monkey.org">Libevent-users@monkey.org</a><br><a href="http://monkey.org/mailman/listinfo/libevent-users">http://monkey.org/mailman/listinfo/libevent-users</a><br><br><br><br></blockquote>
</div><br>