don't abort on failed EPOLL_CTL_MOD

EPOLL_CTL_MOD is used to monitor an fd's writeable status when write was
blocked, but due to a race condition it's possible that the same fd gets
closed by another thread at the same time, causing the EPOLL_CTL_MOD to
fail. As this is now expected, handle it appropriately.

fixes #684

Change-Id: I1ddf16fdbf0fe3e98b4d908544735b823c4cf539
pull/688/head
Richard Fuchs 7 years ago
parent 62e5c9a703
commit 5c556ef4cf

@ -340,12 +340,11 @@ int poller_poll(struct poller *p, int timeout) {
ZERO(e); ZERO(e);
e.events = epoll_events(NULL, it); e.events = epoll_events(NULL, it);
e.data.fd = it->item.fd; e.data.fd = it->item.fd;
if (epoll_ctl(p->fd, EPOLL_CTL_MOD, it->item.fd, &e)) int ret = epoll_ctl(p->fd, EPOLL_CTL_MOD, it->item.fd, &e);
abort();
mutex_unlock(&p->lock); mutex_unlock(&p->lock);
if (it->item.writeable) if (ret == 0 && it->item.writeable)
it->item.writeable(it->item.fd, it->item.obj, it->item.uintp); it->item.writeable(it->item.fd, it->item.obj, it->item.uintp);
} }
else if ((ev->events & POLLIN)) else if ((ev->events & POLLIN))
@ -387,8 +386,7 @@ void poller_blocked(struct poller *p, int fd) {
ZERO(e); ZERO(e);
e.events = epoll_events(NULL, p->items[fd]); e.events = epoll_events(NULL, p->items[fd]);
e.data.fd = fd; e.data.fd = fd;
if (epoll_ctl(p->fd, EPOLL_CTL_MOD, fd, &e)) epoll_ctl(p->fd, EPOLL_CTL_MOD, fd, &e);
abort();
fail: fail:
mutex_unlock(&p->lock); mutex_unlock(&p->lock);

Loading…
Cancel
Save