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

目录
相关文章
|
人工智能 前端开发 测试技术
如何用AI Coding和Claude Code提升开发效率?看我的全流程复盘
本文分享了作者在人工智能编程(AI Coding)领域的实践经验,尤其是使用 Claude Code 提升开发效率的技巧。内容涵盖 Prompt 工程、任务边界划分、上下文管理、代码审查、版本控制等方面,并介绍了 Claude Code 的安装、配置及多任务协作策略,帮助开发者更好地利用 AI 工具提升编程效率与代码质量。
|
机器学习/深度学习 算法 vr&ar
深度学习之可微渲染
可微渲染(Differentiable Rendering)是深度学习领域的一个重要概念,它将传统的计算机图形学与深度学习结合起来,通过使渲染过程可微分(differentiable),以便于在深度学习模型的训练中使用反向传播算法。可微渲染在计算机视觉、图形学和机器人学等领域有着广泛的应用。
1290 3
|
前端开发 Java 关系型数据库
基于JSP和MySQL的学生信息管理系统
基于JSP和MySQL的学生信息管理系统
835 0
基于JSP和MySQL的学生信息管理系统
|
弹性计算
飞天加速计划·高校学生在家实践
飞天加速计划·高校学生在家实践
298 0
飞天加速计划·高校学生在家实践
|
SQL Oracle 关系型数据库
|
2天前
|
监控 网络协议 算法
2026年起SSL证书有效期逐年缩短:企业如何避免“续期风暴”!
SSL证书有效期将从2026年起分三阶段逐步缩短至47天,人工续期难以为继。阿里云“WoSign SSL证书+自动化服务”,支持域名监控、自动托管、云产品/服务器一键部署及智能提醒,助力企业高效应对高频续期挑战。
8071 2
|
11天前
|
域名解析 人工智能 Linux
|
21天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
18561 64
|
19天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置