On Tue, Apr 20, 2010 at 01:20:21PM -0400, Nick Mathewson wrote: > On Mon, Apr 19, 2010 at 11:24 PM, Denis Bilenko <[email protected]> > wrote: > > Hi, > > > > I've run into an issue where event_add() fails with ENOENT. > > This happens when a socket reuses a descriptor that was recently > > closed and was used before with another event. > > > > The details are below. The question I have is - what are the ways to > > work around this? > > > > You must never modify an event that is currently pending. If you want > to reassign it, you need to call event_del(), then modify it, then > call event_add(). > > For some backends (like epoll and kqueue) you need to call event_del() > on the event when you close the socket, and then event_add() again,
More specifically, _before_ you close the socket, because the act of closing the socket will also implicitly remove it from the epoll queue, a state change that libevent can't track. In this case event_del() will return a failure when it tries to remove the non-existent descriptor from the epoll queue. Fortunately the order of operations in event_del() is such that the Right Thing(tm) happens anyhow. Thus, transgressions will usually go unpunished--it's rare that people check the return value of event_del(), and there are no other ill effects. *********************************************************************** To unsubscribe, send an e-mail to [email protected] with unsubscribe libevent-users in the body.
