man epoll上的幾個問題


Q1 What happens if you add the same fd to an epoll_set twice? 如果你把相同的文件描述符添加到epoll中兩次會發生什麼?A1 You will probably get EEXIST. However, it is possible that two threads may add the same fd twice. This is a harmless condition. 你可能會得到一個EEXIST返回標誌,也可能兩個進程添加相同的文件描述符兩次。這種情況是無害的。Q2 Can two epoll sets wait for the same fd? If so, are events reported to both epoll sets fds? 兩個epoll能夠等待相同的描述符嗎?如果這樣,事件會通知到兩個epoll嗎?A2 Yes. However, it is not recommended. Yes it would be reported to both. 是的。但是不建議這樣使用。確實會將事件通知兩個epoll。Q3 Is the epoll fd itself poll/epoll/selectable? epoll描述符本身能被poll、epoll、select使用嗎?A3 Yes. 是的。Q4 What happens if the epoll fd is put into its own fd set? 如果把epoll描述符本身放入它自己的描述符集中會發生什麼?A4 It will fail. However, you can add an epoll fd inside another epoll fd set. 將會失敗。但是你可以把它添加到另外一個epoll描述符集合中。Q5 Can I send the epoll fd over a unix-socket to another process? 我能夠通過一個unix-socket把一個epoll描述符發送給另一個進程嗎?A5 No. 不能。Q6 Will the close of an fd cause it to be removed from all epoll sets automatically? 關閉一個描述符會不會自動把它從所有相關的epoll中刪除?A6 Yes. 會。Q7 If more than one event comes in between epoll_wait(2) calls, are they combined or reported separately? 如果在兩次epoll_wait()之間有多個事件發生,那麼會把他們整合到一起還是單獨地通知epoll?A7 They will be combined. 會把它們整合到一塊。Q8 Does an operation on an fd affect the already collected but not yet reported events? 對一個描述符的操作會不會影響那些已經被收集但是還沒上報的事件?A8 You can do two operations on an existing fd. Remove would be meaningless for this case. Modify will re-read available I/O. 你能對已經存在的描述符做兩種操作。移除對這種情況是沒有什麼意義的。修改將會重讀有效的I/O。Q9 Do I need to continuously read/write an fd until EAGAIN when using the EPOLLET flag ( Edge Triggered behaviour ) ? 使用ET模式時需不需要連續地讀或寫一個文件描述符,直到收到EAGAIN?A9 No you don't. Receiving an event from epoll_wait(2) should suggest to you that such file descriptor is ready for the requested I/O operation. You have simply to consider it ready until you will receive the next EAGAIN. When and how you will use such file descriptor is entirely up to you. Also, the condition that the read/write I/O space is exhausted can be detected by checking the amount of data read/write from/to the target file descriptor. For example, if you call read(2) by asking to read a certain amount of data and read(2) returns a lower number of bytes, you can be sure to have exhausted the read I/O space for such file descriptor. Same is valid when writing using the write(2) function.不需要。從epoll_wait()收到一個事件只是告訴你這個文件描述符已經準備好了所要求的I/O操作。你只需要考慮它是準備好的,直到收到下一個EAGAIN。什麼時候怎樣使用這個文件描述符完全取決於你。另外,可以通過檢測讀/寫目標文件描述符的數據量來探知讀寫IO空間的使用狀況。例如,你通過調用read()函數來請求讀一定量的數據,而read()函數返回了小於請求量的數據,此時你能夠確定已經用盡了這個文件描述符的讀IO空間。使用write()函數來寫有類似的狀況。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章