#include <sys/epoll.h>

int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);
作用:
这个系统调用用于操作epoll函数所生成的实例(该实例由epfd指向),向fd实施op操作。
参数一:epfd
由epoll调用产生的文件描述符
参数二:op
操作的类型,具体包含
EPOLL_CTL_ADD
Register the target file descriptor fd on the epoll instance
referred to by the file descriptor epfd and associate the
event event with the internal file linked to fd. EPOLL_CTL_MOD
Change the event event associated with the target file
descriptor fd. EPOLL_CTL_DEL
Remove (deregister) the target file descriptor fd from the
epoll instance referred to by epfd. The event is ignored and
can be NULL (but see BUGS below).
参数三:fd
op实施的对象
参数四:event
struct epoll_event {
__uint32_t events; /* Epoll events */
epoll_data_t data; /* User data variable */
}; events成员变量:
可以是以下几个宏的集合:
EPOLLIN :表示对应的文件描述符可以读(包括对端SOCKET正常关闭);
EPOLLOUT:表示对应的文件描述符可以写;
EPOLLPRI:表示对应的文件描述符有紧急的数据可读(这里应该表示有带外数据到来);
EPOLLERR:表示对应的文件描述符发生错误;
EPOLLHUP:表示对应的文件描述符被挂断;
EPOLLET: 将EPOLL设为边缘触发(Edge Triggered)模式,这是相对于水平触发(Level Triggered)来说的。
EPOLLONESHOT:只监听一次事件,当监听完这次事件之后,如果还需要继续监听这个socket的话,需要再次把这个socket加入到EPOLL队列里。 data成员变量:
是一个union类型的变量,类型定义如下
typedef union epoll_data {
    void *ptr;
    int fd;
    __uint32_t u32;
    __uint64_t u64;
} epoll_data_t;

参考资料

http://www.man7.org/linux/man-pages/man7/epoll.7.html

epoll_ctl函数的使用的更多相关文章

  1. I/O多路复用——epoll函数

    1 select的低效率 select/poll函数效率比较低,主要有以下两个原因: (1)调用select函数后需要对所有文件描述符进行循环查找 (2)每次调用select函数时都需要向该函数传递监 ...

  2. epoll函数及三种I/O复用函数的对比

    epoll函数 #include <sys/epoll.h>int epoll_create(int size)int epoll_ctl(int epfd, int op, int fd ...

  3. 网络编程API-下 (I/O复用函数)

    IO复用是Linux中的IO模型之中的一个,IO复用就是进程预先告诉内核须要监视的IO条件,使得内核一旦发现进程指定的一个或多个IO条件就绪,就通过进程进程处理.从而不会在单个IO上堵塞了. Linu ...

  4. UNIX网络编程——epoll 系列函数简介、与select、poll 的区别

    前面博客<<UNIX环境高级编程--epoll函数使用详解>>有关于epoll函数的讲解. 一.epoll 系列函数简介 #include <sys/epoll.h> ...

  5. 详解网络编程必会的poll和epoll函数

    前言 之前已经介绍过select函数,请参考这篇博客:https://www.cnblogs.com/liudw-0215/p/9661583.html,原理都是类似的,有时间先阅读下那篇博客,以便于 ...

  6. epoll 系列函数简介、与select、poll 的区别

    一.epoll 系列函数简介 #include <sys/epoll.h> int epoll_create(int size); int epoll_create1(int flags) ...

  7. c++ 网络编程(八) LINUX-epoll/windows-IOCP下 socket opoll函数用法 优于select方法的epoll 以及windows下IOCP 解决多进程服务端创建进程资源浪费问题

    原文作者:aircraft 原文链接:https://www.cnblogs.com/DOMLX/p/9622548.html 锲子:关于并发服务器中的I/O复用实现方式,前面在网络编程系列四还是五来 ...

  8. epoll 函数解析

    本文参考社长的 TinyWebServer 庖丁解牛 epoll 常用API epoll_create 函数 #include <sys/epoll.h> int epoll_create ...

  9. select、poll、epoll之间的区别总结

    select.poll.epoll之间的区别总结 05/05. 2014 select,poll,epoll都是IO多路复用的机制.I/O多路复用就通过一种机制,可以监视多个描述符,一旦某个描述符就绪 ...

随机推荐

  1. 用于未处理异常错误的.NET框架清理工具

    当你启动某些程序时,会收到与此错误类似的未处理异常错误:Unhandled e0434f4dh exception at 7c81eb33h.此问题是由于.NET框架未正确安装或.NET框架系统中的另 ...

  2. Using HAProxy as an API Gateway, Part 2 [Authentication]

    转自:https://www.haproxy.com/blog/using-haproxy-as-an-api-gateway-part-2-authentication/ HAProxy is a ...

  3. leetcode题目讲解(Python):字符串转整数 (atoi)

    分析这道题,输入数据有如下几种情况: 第一类:输入字符串无法转换为整数 这一类包含以下几种情况: 输入字符串为空 开头字符为数字.符号(+,-).空格以外的字符 有多个加减符号的字符串 符号没有紧跟数 ...

  4. eclipse为项目设置jdk

    1)在项目上右键选中properties,会进入如下界面 (2)然后点击Add Library,进入设置Library的界面 (3)选中JRE System Library进入下一界面就可以设置jdk ...

  5. Atcoder Regular Contest 060 F题第一问答案证明

    一切的开始 令 \(x\) 为字符串,\(p\) 为正整数.如果对于满足 \(0\le i<|x|−p\) 的任何整数 \(i\) 满足 \(x[i]=x[i+p]\),则 \(p\) 称为 \ ...

  6. Nessus简单使用

    1.更新插件 上次搭建完后总觉得不踏实,因为老是提示插件多久没更新了,然后果断花了1.25美刀买了台vps,终于把最新的插件下载下来了,总共190M,需要的QQ私信我.

  7. node省市区三级数据性能测评

    闲来无事,测试下node和egg 首先是数据库,大概长这样 然后是代码 'use strict'; const Controller = require('egg').Controller; clas ...

  8. The fileSyncDll.ps1 is not digitally signed. You cannot run this script on the current system.

    https://www.opentechguides.com/how-to/article/powershell/105/powershel-security-error.html Unblockin ...

  9. python selenium chrome 实现自动化登录

    1.环境安装 selenium的开发文档网址(英语好的可以直接看这个,写的很详细):http://selenium-python.readthedocs.io/ 因为实现的时候使用的是谷歌浏览器,在运 ...

  10. k8s 传参给docker env command、args和dockerfile中的entrypoint、cmd之间的关系

    [k8s]args指令案例-彻底理解docker entrypoint     需求: 搞个镜像,可以运行java -jar xxx.jar包,xxx.jar包名称要用参数传 思路1: 打对应运行ja ...