2016-08-06 32 views
0

epoll_insert功能被sys_epoll_ctl調用。關於epoll_insert的詳細功能

有在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++; 
    } 
    

我不明白爲什麼要檢查文件是否在epoll_insert功能做好準備。我們應該在ep_poll_callback函數中檢查它嗎?

回答

2

ep_poll_callback僅在其中一個文件描述符的狀態更改時才被調用。如果這是epoll描述符被添加到讀取列表的唯一地方,那麼您可能會錯過在設法將它們添加到epoll之前發生的事件。例如,在Web服務器中,如果客戶端連接後立即發送請求,則可能會錯過客戶端的請求。