<div>You could call event_init immediately after you fork in a child to get a fresh libevent instance.&nbsp; 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.&nbsp; When registering a new event you must first set the appropriate base with event_base_set.&nbsp; 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.&nbsp; 
</div>
<div>&nbsp;</div>
<div>This approach is based upon my understanding of how libevent works internally, I&#39;ve never actually used it with epoll on Linux, only devpoll on Solaris which is similar.&nbsp;&nbsp;If it works, your children will inherit the parent&#39;s epoll fd but just ignore it.&nbsp; Not sure if that&#39;s the behavior you&#39;d like.&nbsp; I&#39;m also a bit curious why you&#39;re using libevent in the first place if the architecture of your app is such that it forks for each client.&nbsp; libevent, and event based programming in general, allow you to service multiple clients from the same process quite easily.
</div>
<div>&nbsp;</div>
<div>Andrew<br>&nbsp;</div>
<div><span class="gmail_quote">On 1/22/07, <b class="gmail_sendername">Wilmer van der Gaast</b> &lt;<a href="mailto:wilmer@gaast.net">wilmer@gaast.net</a>&gt; 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&#39;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&#39;s more than one client.<br><br>With only one client everything works perfectly, but once there&#39;s<br>another one, process 1 seems to get the other process&#39; 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&#39;t expect to get such an error in a &quot;there&#39;s data, read<br>it&quot; 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&#39;m wondering, how do I make sure every process gets its own<br>epfd? I found epoll_base_free(), but it&#39;s probably not what I&#39;m looking<br>for, because of this line:<br><br>assert(TAILQ_EMPTY(&amp;base-&gt;eventqueue));
<br><br>This means that I have to remove all event handlers to make this<br>function call successful, right? I really shouldn&#39;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>+-------- .&#39;&#39;`.&nbsp;&nbsp;&nbsp;&nbsp; - -- ---+&nbsp;&nbsp;+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- -- --- ---- ----- ------+
<br>| wilmer : :&#39;&nbsp;&nbsp;:&nbsp;&nbsp;<a href="http://gaast.net">gaast.net</a> |&nbsp;&nbsp;| OSS Programmer&nbsp;&nbsp; <a href="http://www.bitlbee.org">www.bitlbee.org</a> |<br>| lintux `. `~&#39;&nbsp;&nbsp;<a href="http://debian.org">debian.org</a> |&nbsp;&nbsp;| Full-time geek&nbsp;&nbsp;
<a href="http://wilmer.gaast.net">wilmer.gaast.net</a> |<br>+--- -- -&nbsp;&nbsp;` ---------------+&nbsp;&nbsp;+------ ----- ---- --- -- -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+<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>