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()函数来写有类似的状况。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章