EPOLL_CREATE(2) Linux Programmer's Manual EPOLL_CREATE(2)

  • 名字

    epoll_create, epoll_create1 - open an epoll file descriptor

  • 梗概

#include <sys/epoll.h>

int epoll_create(int size);
int epoll_create1(int flags);
  • 描述:

    epoll_create() creates an epoll(7) instance(实例). Linux 2.6.8 及以后的版本size参数被忽略, 但是必须大于0;看下面的’注意’.
    epoll_create() 返回一个新epoll实例相关的文件描述符,这个文件描述符用在所有随后的函数调用,不在使用的时候,文件描述符应用close()关闭,所有文件描述符关闭的时候(意思是引用计数减到0时),内核将销毁实例并释放相关资源。

  • epoll_create1()

    If flags is 0, then, other than the fact that the obsolete(废弃的) size argument is dropped, epoll_create1() is the same as epoll_create(). flag取下面的值可以用来获取不同的行为:

    • EPOLL_CLOEXEC

      • Set the close-on-exec (FD_CLOEXEC) flag on the new file descriptor. See the description of the O_CLOEXEC flag in open(2) for reasons why this may be useful.
    • RETURN VALUE

      • 成功返回一个非负的描述符,失败返回-1,同时errno被设置
    • ERRORS
    • EINVAL size is not positive.
      • EINVAL (epoll_create1()) Invalid(无效) value specified in flags.
    • EMFILE The per-user limit on the number of epoll instances imposed by /proc/sys/fs/epoll/max_user_instanceswas encountered(冲突). See epoll(7) for further details.
    • EMFILE The per-process limit on the number of open file descriptors has been reached.

    • ENFILE The system-wide limit on the total number of open files has been reached.

    • ENOMEM There was insufficient memory to create the kernel object.

  • 版本:

    • epoll_create() 是在linux 2.6加进内核的.Library support is provided in glibc starting with version 2.3.2.

    • epoll_create1() was added to the kernel in version 2.6.27. Library support is provided in glibc starting with version 2.9.

  • CONFORMING TO

    • epoll_create() is Linux-specific.
  • 注意

    • In the initial epoll_create() implementation, 参数 size 告诉内核函数调用希望加到实例的描述符个数,内核用这个信息作为依据用于在初始化时申请结构events空间. (如果有必要,内核会申请更多的空间如果函数使用超过size),现在这个参数已经没有必要了,但是还是要大于0以保证向前的兼容性。
  • SEE ALSO
    close(2), epoll_ctl(2), epoll_wait(2), epoll(7)

  • COLOPHON

    • This page is part of release 4.04 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page,can be found at http://www.kernel.org/doc/man-pages/.

Linux 2015-12-28 EPOLL_CREATE(2)

`epoll_create` 和 `epoll_create1` 都是 Linux 系统中的用于创建 epoll 实例的系统调用。它们的主要区别在于: 1. **兼容性**: - `epoll_create` 是早期版本的 epoll 创建函数,在 Linux 2.6 内核之前存在,需要手动设置一些标志位,如 EPOLL_CLOEXEC 来控制文件描述符的行为。 - `epoll_create1` 是引入在内核 2.6.19 版本之后,它提供了一个更现代、简洁的接口,可以一次性指定更多的选项。 2. **功能参数**: - `epoll_create` 需要传递一个整数参数,表示最大事件数量。如果超过这个限制,可能会失败。 - `epoll_create1` 可以直接传入一个标志位(EPOLL_CLOEXEC 或 EPOLL_LEVEL | EPOLL_ONESHOT),使得创建出来的 epoll 文件描述符默认关闭(仅适用于新式系统)。 3. **错误处理**: - `epoll_create` 的错误处理相对复杂,因为它不带错误检查。 - `epoll_create1` 更明确地返回 -1 并设置errno来指示错误,比如当参数无效或者资源不足时。 4. **安全性与便利性**: - `epoll_create1` 提供了更好的错误处理机制,同时也简化了一些安全选项的设置,使得使用更为方便。 总的来说,`epoll_create1` 是对 `epoll_create` 的改进,建议在支持该函数的新系统上优先选择,因为它提供了一种更加现代的方式来处理事件监听。如果你的项目需要兼容较旧的Linux版本,或者需要更详细的错误处理,那么 `epoll_create` 仍可能是必要的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值