[Libevent-users] event_add() failure return handling

M.H.VanLeeuwen mhvl at sbcglobal.net
Tue Sep 18 23:10:42 EDT 2007


Hi,

When event_add(&ev, &tv) returns -1, what is the proper way to clean up.

For example function XYZZY() takes socket fd as an argument

XYZZY(int sockfd)
{
allocate event structure related memory...
...
       event_set(&(event->event), sockfd, EV_TIMEOUT | EV_WRITE | 
EV_PERSIST, connected, &(event->event));
       ret = event_base_set(event_base, &(event->event));

       if (ret == 0)
       {
           ret = event_add(&(event->event), &CONNECT_WAIT);
       }

      if (ret != 0)
      {
// What is the proper action to take here?
             return FAIL;
       }
...
      return SUCCESS;
}
-------------

The reason I ask is that it seems event_add() will continue to time for 
CONNECT_WAIT time
even if it returns -1, failure.  Shouldn't event_add(), on return of -1, 
unwind from the timer that
it has started?

Thanks,
Martin


More information about the Libevent-users mailing list