Why does ngx_epoll_del_event use EPOLL_CTL_MOD

Qiying Wang qiyingwangwqy at gmail.com
Mon Oct 28 07:25:27 UTC 2019


Hello!

ngx_epoll_del_event is a function to delete an event. Deleting an event
means unregister the file descriptor from epoll therefore it would not be
triggered unless being added again. But EPOLL_CTL_MOD won't remove the
event as far as I know. It seems the event would be triggered in the next
processing loop. So why use EPOLL_CTL_MOD here rather than just
EPOLL_CTL_DEL?

The source code is located in `src/event/modules/ngx_epoll_module.c`

static ngx_int_t
ngx_epoll_del_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
{
    // ......

    if (e->active) {
        op = EPOLL_CTL_MOD;
        ee.events = prev | (uint32_t) flags;
        ee.data.ptr = (void *) ((uintptr_t) c | ev->instance);

    } else {
        op = EPOLL_CTL_DEL;
        ee.events = 0;
        ee.data.ptr = NULL;
    }

    ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
                   "epoll del event: fd:%d op:%d ev:%08XD",
                   c->fd, op, ee.events);

    if (epoll_ctl(ep, op, c->fd, &ee) == -1) {
        ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
                      "epoll_ctl(%d, %d) failed", op, c->fd);
        return NGX_ERROR;
    }

    ev->active = 0;

    return NGX_OK;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20191028/b3ad1b5e/attachment.htm>


More information about the nginx-devel mailing list