Fix lwevent_set_events().

This function should only update the lwevent structure's event mask if
the call to epoll_ctl() succeeds. This does, however, mean that the
event mask cannot be changed if the lwevent instance is deactivated.
This commit is contained in:
Laurence Withers 2007-10-26 13:20:56 +00:00
parent f8f6e4aa3b
commit 5ed8cef02f
1 changed files with 16 additions and 6 deletions

View File

@ -44,19 +44,29 @@ int lwevent_get_autodestroy(const struct lwevent* ev)
/* lwevent_set_events()
* Calls epoll_ctl(EPOLL_CTL_MOD) to change the events associated with the object `ev'. Does not
* perform the call if the new events match the current events. If `old_events' is not null, stores
* the existing events before changing. Returns -1 if epoll_ctl fails.
* perform the call if the new events match the current events. Returns -1 if epoll_ctl fails.
*/
int lwevent_set_events(struct lwevent* ev, int events)
{
if(events == ev->events) return 0; /* don't call epoll_ctl() if no change */
return _lwevent_activate(EPOLL_CTL_MOD, ev);
struct epoll_event ee;
/* don't call epoll_ctl() if no change */
if(events == ev->events) return 0;
/* try the modification */
ee.events = events;
ee.data.ptr = ev;
if(TEMP_FAILURE_RETRY( epoll_ctl(lwevent_epoll_fd, EPOLL_CTL_MOD, ev->fd, &ee) )) return -1;
/* update structure only if it succeeded */
ev->events = events;
return 0;
}
/* lwevent_set_*()
* Changes attributes associated with `ev', possibly storing the old value.
* Changes attributes associated with `ev'.
*/
void lwevent_set_callback(struct lwevent* ev, lwevent_callback callback)
{