关于epoll_insert的详细函数

The detail function about epoll_insert

epoll_insert 函数被 sys_epoll_ctl 调用。

epoll_insert函数中有一些关键步骤:

  1. 使用队列回调初始化轮询table:ep_ptable_queue_proc

  2. 它会调用 file->f_op->poll

  3. 如果文件已经是 "ready" ,那么我们将其放入就绪列表

    /* If the file is already "ready" we drop it inside the ready list */
    if ((revents & event->events) && !ep_is_linked(&epi->rdllink)) {
    
        list_add_tail(&epi->rdllink, &ep->rdllist);
    
        /* Notify waiting tasks that events are available */
        if (waitqueue_active(&ep->wq))
            wake_up_locked(&ep->wq);
        if (waitqueue_active(&ep->poll_wait))
            pwake++;
    }
    

我不明白为什么要在 epoll_insert 函数中检查文件是否就绪。我们应该在 ep_poll_callback 函数中检查它吗?

ep_poll_callback 仅在其中一个文件描述符的状态发生变化时调用。如果那是唯一将 epoll 描述符添加到读取列表的地方,您可能会错过在设法将它们添加到 epoll 之前发生的事件。例如,在 Web 服务器中,如果在连接后立即发送客户端请求,您可能会错过该请求。