epoll_ctl函数的使用
#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函数的使用的更多相关文章
- I/O多路复用——epoll函数
1 select的低效率 select/poll函数效率比较低,主要有以下两个原因: (1)调用select函数后需要对所有文件描述符进行循环查找 (2)每次调用select函数时都需要向该函数传递监 ...
- epoll函数及三种I/O复用函数的对比
epoll函数 #include <sys/epoll.h>int epoll_create(int size)int epoll_ctl(int epfd, int op, int fd ...
- 网络编程API-下 (I/O复用函数)
IO复用是Linux中的IO模型之中的一个,IO复用就是进程预先告诉内核须要监视的IO条件,使得内核一旦发现进程指定的一个或多个IO条件就绪,就通过进程进程处理.从而不会在单个IO上堵塞了. Linu ...
- UNIX网络编程——epoll 系列函数简介、与select、poll 的区别
前面博客<<UNIX环境高级编程--epoll函数使用详解>>有关于epoll函数的讲解. 一.epoll 系列函数简介 #include <sys/epoll.h> ...
- 详解网络编程必会的poll和epoll函数
前言 之前已经介绍过select函数,请参考这篇博客:https://www.cnblogs.com/liudw-0215/p/9661583.html,原理都是类似的,有时间先阅读下那篇博客,以便于 ...
- epoll 系列函数简介、与select、poll 的区别
一.epoll 系列函数简介 #include <sys/epoll.h> int epoll_create(int size); int epoll_create1(int flags) ...
- c++ 网络编程(八) LINUX-epoll/windows-IOCP下 socket opoll函数用法 优于select方法的epoll 以及windows下IOCP 解决多进程服务端创建进程资源浪费问题
原文作者:aircraft 原文链接:https://www.cnblogs.com/DOMLX/p/9622548.html 锲子:关于并发服务器中的I/O复用实现方式,前面在网络编程系列四还是五来 ...
- epoll 函数解析
本文参考社长的 TinyWebServer 庖丁解牛 epoll 常用API epoll_create 函数 #include <sys/epoll.h> int epoll_create ...
- select、poll、epoll之间的区别总结
select.poll.epoll之间的区别总结 05/05. 2014 select,poll,epoll都是IO多路复用的机制.I/O多路复用就通过一种机制,可以监视多个描述符,一旦某个描述符就绪 ...
随机推荐
- S1_搭建分布式OpenStack集群_07 nova服务配置 (计算节点)
一.服务安装(计算节点)安装软件:# yum install openstack-nova-compute -y 编辑/etc/nova/nova.conf文件并设置如下内容:# vim /etc/n ...
- BZOJ 5287: [Hnoi2018]毒瘤 动态dp(LCT+矩阵乘法)
自己 yy 了一个动态 dp 做法,应该是全网唯一用 LCT 写的. code: #include <bits/stdc++.h> #define ll long long #define ...
- repo源
[sdata-base] name=Base baseurl=http://xx.xx.xx.xx:4507/repo/$releasever/$basearch/base enabled=1 gpg ...
- C博客作业02—循环结构
0.展示PTA总分(0----2) 截图展示2次题目集:单循环和嵌套循环题目集,排名分数截图. 1.本章学习总结(2分) 1.1 学习内容总结 整理这两周学习主要知识点,并能对每个知识点介绍简单案例或 ...
- GoCN每日新闻(2019-10-26)
GoCN每日新闻(2019-10-26) 1. GateKeeper:滴滴开源的使用Go编写的不依赖分布式数据库的API网关 https://mp.weixin.qq.com/s/gpQSPJ-uRp ...
- JDK 下载相关资料
所有版本JDK下载地址: http://www.oracle.com/technetwork/java/archive-139210.html 下载账户密码: 2696671285@qq.com Or ...
- 微信小程序 Flex局部元素被挤压问题
关于Flex布局不在此处赘述,需要了解的可以查阅官方文档:基本的布局方法——Flex布局 当使用Flex布局,想实现如下图1的效果时,代码编写如下: 图1: <!-- wxml文件 --> ...
- avalon用background-image不起作用,怎么来选取前几个的图片进行渲染
<span ms-css="{backgroundImage: 'url('+item.image + ')'}" ms-for="($index,item) in ...
- Codeforces 839D Winter is here - 暴力 - 容斥原理
Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n s ...
- 【NQG】Paragraph-level Neural Question Generation with Maxout Pointer and Gated Self-attention Networks论文笔记
这篇文章主要处理了在问题生成(Question Generation,QG)中,长文本(多为段落)在seq2seq模型中表现不佳的问题.长文本在生成高质量问题方面不可或缺. 1. Introducti ...