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

目录
相关文章
|
11月前
|
存储 缓存 监控
深入了解MySQL内存管理:如何查看MySQL使用的内存
深入了解MySQL内存管理:如何查看MySQL使用的内存
1142 1
|
设计模式 人工智能 JSON
一文掌握大模型提示词技巧:从战略到战术
本文将用通俗易懂的语言,带你从战略(宏观)和战术(微观)两个层次掌握大模型提示词的常见技巧,真正做到理论和实践相结合,占领 AI 运用的先机。
239723 5
|
消息中间件 存储 监控
|
安全 API 数据安全/隐私保护
大咖与小白的日常:号码隐私保护是如何实现的?
快递、外卖、打车……我们的隐私安全真的有保障吗?虚拟号码是如何实现的?
864 0
|
SQL 存储 Oracle
数据分析基础--SQL
我们在做数据分析的工作时,会用到大量的数据,而这些数据都来自于数据库,SQL可以让我们很方便的去访问和查询数据库。 作为一个数据分析师,我们需要掌握一些SQL的核心技能
|
C# Windows
推荐一个C#开发的窗口扩展菜单,支持系统所有窗口
一个C#开发的窗口扩展项目,采用.NET Framework 4.0开发,支持Windows Xp以及更高版本的系统,同时支持命令模式,可供代码调用。
193 0
推荐一个C#开发的窗口扩展菜单,支持系统所有窗口
|
Java 容器 Spring
SpringloC容器的依赖注入源码解析(9)—— populateBean
站在设计者的角度设计populateBean: 调用Bean的Setter方法实例去给Bean设置上属性值 变量类型的转换,同时还要考虑处理集合类型的情况
SpringloC容器的依赖注入源码解析(9)—— populateBean
|
存储 数据库 双11
2.0 解析系列终篇 | OceanBase 2.0 到底如何做到 50% 的性能提升?
OB君:今天的终篇我们来聊聊最重要的OceanBase 2.0在性能优化方面所展开的工作,以及OceanBase是如何实现极致性能的。本文整理自10月27日OceanBase TechTalk北京站活动中颜然的演讲《OceanBase 2.0的性能突破》。
《从零开始学Swift》学习笔记(Day 25)——类和结构体定义
<div style="top: 0px;"></div> <span lang="EN-US"><span style="font-family:Cambria;font-size:14px;"></span></span><p style="margin: 0cm 0cm 0pt;"><span style="font-family:宋体;font-size: 14pt; mso-as
1518 0
|
SQL Perl
普通表转换为分区表
yang@ORACL> create table yangtmp ( id number, time date );表已创建。yang@ORACL> insert into yangtmp select rownum id ,sysdate-dbms_random.value(1,500) time  2  from dual  3  connect by level 已创建100000行。
750 0