8、关于epoll的专家问答

简介: Q1    What happens if you add the same fd to an epoll_set twice?     A1    You will probably get EEXIST.

    Q1    What happens if you add the same fd to an epoll_set twice?

    A1    You will probably get EEXIST. However, it is possible that two threads may add the same fd twice. This is a harmless condition. (同一个fd可以设置两次)

    Q2    Can two epoll sets wait for the same fd? If so, are events reported to both epoll sets fds?

    A2    Yes. However, it is not recommended. Yes it would be reported to both. (同一个fd可以被两个epoll 集等待)

    Q3    Is the epoll fd itself poll/epoll/selectable?

    A3    Yes. (epoll fd 同普通fd一样,可设置,意为可用epoll_ctl

    Q4    What happens if the epoll fd is put into its own fd set?

    A4    It will fail. However, you can add an epoll fd inside another epoll fd set.

    Q5    Can I send the epoll fd over a unix-socket to another process?

    A5    No. (只能在本进程使用)

    Q6    Will the close of an fd cause it to be removed from all epoll sets automatically?

    A6    Yes. (智能删除)

    Q7    If more than one event comes in between epoll_wait(2) calls, are they combined or reported separately?

    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.

    Q9    Do I need to continuously read/write an fd until EAGAIN when using the EPOLLET flag ( Edge Triggered behaviour ) ?

    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.(也就是说,检测到EAGAIN是一种保险的方法,另一种方法是,读到的字节数比可预期的少,那也说明读缓存空了

参考

【1】http://linux.die.net/man/4/epoll

目录
相关文章
|
5月前
|
存储 监控 Linux
深入理解epoll:高效I/O多路复用的核心技术(上)
深入理解epoll:高效I/O多路复用的核心技术
|
3月前
epoll分析
epoll分析
|
3月前
网络编程-epoll模型
网络编程-epoll模型
|
4月前
|
存储 网络协议 Linux
对epoll相关知识做简单整理
对epoll相关知识做简单整理
27 0
|
4月前
|
存储 Linux
Linux网络编程(epoll函数的使用)
Linux网络编程(epoll函数的使用)
46 0
|
5月前
|
存储 缓存 负载均衡
深入理解epoll:高效I/O多路复用的核心技术(下)
深入理解epoll:高效I/O多路复用的核心技术
|
11月前
|
存储 网络协议 Java
计网 - Socket 编程:epoll 为什么用红黑树?
计网 - Socket 编程:epoll 为什么用红黑树?
111 0
|
缓存 Linux
linux网络编程(五)epoll进阶
linux网络编程(五)epoll进阶
101 0
|
Linux
linux网络编程(六)epoll反应堆
linux网络编程(六)epoll反应堆
143 1
linux网络编程(六)epoll反应堆
|
消息中间件 存储 安全
阿里二面:什么是mmap?
平时在面试中你肯定会经常碰见的问题就是:RocketMQ为什么快?Kafka为什么快?什么是mmap? 这一类的问题都逃不过的一个点就是零拷贝,虽然还有一些其他的原因,但是今天我们的话题主要就是零拷贝。
阿里二面:什么是mmap?