是否epoll的preserve的顺序FD的登记? [英] Does epoll preserve the order in which fd's was registered?

查看:180
本文介绍了是否epoll的preserve的顺序FD的登记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Linux系统调用玩弄我发现的epoll 的某些方面,那就是我也不清楚。我说,我创建了一个的epoll 实例:

I'm playing around with Linux system call and I found some aspect of epoll, that is not clear to me. Say, I create a epoll instance:

epollfd = epoll_create(50);

接下来,我在注册 50文件描述符 -loop:

for(i=0; i<50; i++){
    // open file "file-i".txt
    // construct epoll_event
    // register new file descriptor with epoll_ctl(epollfd, EPOLL_CTL_ADD ...

现在我们有50个文件,是准备行动(读或写 - 无所谓)。我们设置MAX_EVENTS 3:

Now we have 50 file, that are ready for action(read or write -- doesn't matter). We set MAX_EVENTS to 3:

#define MAX_EVENTS 3
...
struct epoll_event events[MAX_EVENTS]
...
epoll_wait(epollfd, events, MAX_EVENTS, -1)

所有这些50个文件的准备,我们只要求他们3个。哪些文件会在事件数组?


  • [1,2,3] - 以第3个文件,他们被添加到epoll的

  • [48,49,50] - 为了最后的3个文件,他们被添加到epoll的

  • [34,7,15 - 3随机文件

  • 其他选项

感谢您。

推荐答案

对于通过的 epoll的时,人们可以看出在准备事件被保持在一个链表。事件从列表的头部移除并添加到列表的末尾。

Perusing through the source file for epoll, one sees that the ready events are maintained in a linked list. Events are removed from the head of the list and added to the end of the list.

在此基础上,得到的答复是,描述顺序是根据它们成为现成的顺序。

Based on that, the answer is that the descriptor order is based on the order in which they became ready.

这篇关于是否epoll的preserve的顺序FD的登记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆