- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
有没有一种方法可以复制使用 epoll_create
创建的文件描述符,以便可以修改副本(使用 epoll_ctl
添加/删除监视的文件描述符)独立。
例如我创建了一个 epoll 文件描述符 A
,它等待文件 P
和 Q
上的事件。我将它复制到 epoll 文件描述符 B
,并使 B
也等待文件 R
上的事件。调用 epoll_wait(A)
仍然只会等待 P
和 Q
。
这是在 A
上调用 dup
时的行为,还是需要使用 epoll_create
和 重新创建 epoll 文件描述符epoll_ctl
?
最佳答案
这有点令人困惑。
当您打开一个新文件时,会创建两个实体。一个是内核中的文件句柄。另一个是文件描述符,一个引用该文件句柄的数字。
虽然我不确定 epoll fd 会发生什么,但我假设它与任何其他重复的 fd 相同,那就是它们是相同的文件句柄。
关于这一点的提示,epoll(2)
手册页的摘录可能会有所帮助:
Q6 Will closing a file descriptor cause it to be removed from all epoll sets automatically?
A6 Yes, but be aware of the following point. A file descriptor is a reference to an open file description (see
open(2)
). Whenever a descriptor is duplicated viadup(2)
,dup2(2)
,fcntl(2)
F_DUPFD
, orfork(2)
, a new file descriptor referring to the same open file description is created. An open file description continues to exist until all file descriptors referring to it have been closed. A file descriptor is removed from an epoll set only after all the file descriptors referring to the underlying open file description have been closed (or before if the descriptor is explicitly removed usingepoll_ctl(2)
EPOLL_CTL_DEL
).
This means that even after a file descriptor that is part of an epoll set has been closed, events may be reported for that file descriptor if other file descriptors referring to the same underlying file description remain open.
所以,虽然我自己没有检查过,但我猜测 dup
不允许您以任何方式复制 epoll 的过滤器列表。两个 fd
将引用相同的文件句柄。对一个过滤器所做的任何更改都会反射(reflect)在另一个过滤器中。
不幸的是,由于我知道没有 API 可以查询 epoll
的过滤器列表,这意味着你无法做你想做的事,除了从头开始跟踪.
关于c - 复制 epoll 文件描述符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37787619/
我正在使用 epoll 编写媒体服务器。 fds 都设置为非阻塞,我正在使用边缘触发事件。我知道对于 EPOLLIN,我需要循环读取 fd,直到返回 EAGAIN。但是写作呢? 当我想写入时,我将数据
很难说出这里问的是什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。如需帮助澄清此问题以便可以重新打开,visit the help center . 8年前关闭
简短的问题,但对我来说很难理解。 为什么 ePoll 的扩展性比 Poll 更好? 最佳答案 poll 系统调用每次都需要将您的文件描述符列表复制到内核。这只会发生一次 epoll_ctl ,但不是每
情况: 多个进程共享同一个文件描述符表。 每个进程监听自己的 epoll 实例。 所有套接字和涉及它们的调用都是非阻塞的。 在这些进程中,只有进程A将监听套接字添加到它的epoll实例。 进程 A 知
我有几个线程,其中一个在循环中调用 epoll_wait,其他线程可以打开需要由第一个线程 epoll 的连接。是否可以只使用 epoll_ctl 添加新套接字,而另一个线程在 epoll_wait
众所周知,我们可以将poll/select与Netmap结合使用:http://info.iet.unipi.it/~luigi/netmap/ 是否可以使用epoll以及将epoll与Netmap一
我正在使用 epoll 和大量 fd 编写应用程序。 为了改进 fd 对应用程序相关 DB 的搜索,我想传递给 epoll 应用程序信息,例如 DB 数组中的索引。 我想过使用data->ptr(ep
我有一个多线程 epoll 服务器。我创建了一个 epoll fd,然后我将让 X 个线程休眠,等待 epoll_wait() 来自 SAME epoll fd 的任何事件。 现在我的问题是:如何唤醒
我有两个线程在 epoll 上运行。一个线程尝试与服务器建立 TCP 连接,使用 EPOLL_CTL_ADD 选项将套接字添加到 epoll-fd。 另一个线程负责等待添加到 epoll-fd 的 S
我正在使用 Cassandra,在启动期间,Netty 会打印一 strip 有堆栈跟踪的警告: Found Netty's native epoll transport in the classpa
epoll_wait、select 和 poll 函数都提供超时。然而使用epoll,其分辨率可达1ms。 Select 和 ppoll 是唯一提供亚毫秒级超时的。 这意味着最好以 1 毫秒的间隔做其
我正在使用 epoll 进行网络编程。我想知道检测用户断开连接的最佳方法。现在,我正在使用带有超时的选择来查看接收缓冲区中是否有信号并且在一定时间内没有信号然后关闭套接字连接。 我认为可能还有其他更适
epoll 是 Linux 系统中常用的多路复用 I/O 组件,一般用于监听 socket 是否能够进行 I/O 操作。那么,epoll 能监听普通文件吗? 我们先通过下面的例子来验证一下,e
我正在使用 epoll 将大消息写入使用 HTTP 协议(protocol)的服务器。 fds 都设置为非阻塞,我正在使用边缘触发事件。我知道对于 EPOLLIN,我需要循环读取 fd,直到返回 EA
我使用python的socket和epoll来制作一个Web服务器。我的操作系统是Linux CentOS 6,我的python版本是python 2.7.8。我的源代码是: # -*-coding:
我的 TCP 服务器中有一个 epoll 事件循环来处理客户端连接并从客户端读取数据。 while(1) { int n, i; n = epoll_wait(efd, events,
我有一个项目,我正在从普通的 select() 转换,但由于我运行的测试有超过 1000 个连接,我决定将其更改为 epoll。 我的代码可以正常工作,但遇到了一个问题,我正在尝试找出解决问题的最佳方
我是 linux 系统编程的新手,所以请多多关照。我必须通过 RS-422 在 8N1 模式下以波特率 921600 从串行端口 (/dev/ttyX) 读取数据,没有奇偶校验。stty 输出信号表示
我从here得到了基础知识关于 epoll。我知道epoll可以监控多个FD并处理。 我的问题是:重事件是否会阻塞服务器,所以我必须使用多线程? 例如,服务器的epoll正在监控2个套接字A和B。现在
我正在使用 epoll 进行网络编程。我想知道如何处理客户端断开连接。我阅读了 api 文档,epoll_wait 有一个超时参数。但是,如果 epoll_wait 函数或正在连接的客户端超时,我会感
我是一名优秀的程序员,十分优秀!