On Tue, Sep 18, 2007 at 10:10:42PM -0500, M.H.VanLeeuwen wrote:
> 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 only way to receive a non-zero retval from event_add is if the
underlying event notification mechanism returns a non-zero value
to event_add. In order to determine which event mechanism that is,
we need more information like which OS you're experiencing this under
and/or the particular event mechanism you're using (set the following
shell variable before executing your code: EVENT_SHOW_METHOD=1).

Without knowing more than that all one can say is that if event_add()
returns -1, it is programming error, somewhere. I speculate possibly
your fd is invalid or previously closed or something else is wrong.

> 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?

This is valid. However it's kind of a rare case.

-cl
_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkey.org/mailman/listinfo/libevent-users

Reply via email to