epoll_insert

时间:2016-08-06 03:29:07

标签: linux io linux-kernel linux-device-driver epoll

epoll_insert函数由sys_epoll_ctl调用。

epoll_insert功能中有一些关键步骤:

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

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

  3. 如果文件已经准备就绪" ,然后我们把它放在准备好的列表中

    /* 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++;
    }
    
  4. 我不明白为什么要在epoll_insert函数中检查文件是否准备就绪。我们应该在ep_poll_callback函数中查看吗?

1 个答案:

答案 0 :(得分:2)

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

相关问题