Epoll二(函数使用说明)

创作人QQ:851301776,邮箱:lfr890207@163.com,欢迎大家一起技术交流,本博客主要是自己学习的心得体会,只为每天进步一点点!

个人座右铭:
1.没有横空出世,只要厚积一定发。
2.你可以学历不高,你可以不上学,但你不能不学习

此博客总结,主要是方便日后查看学习
 

一、epoll_ctl函数

#include <sys/epoll.h>

int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);

参数说明:

第一个参数:epoll_create创建的返回值

第二个参数: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中增加一个需要监控的fd,和对应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,需要监控的fd

第四个参数:event

typedef union epoll_data {
               void        *ptr;
               int          fd;
               uint32_t     u32;
               uint64_t     u64;
} epoll_data_t;

struct epoll_event {
               uint32_t     events;      /* Epoll events */
               epoll_data_t data;        /* User data variable */
};

epoll_data_t data,这个结构体有很大的用处,reactor的精妙就在void *ptr,很多人不会使用此块

events说明:

EPOLLIN
        The associated file is available for read(2) operations.
	    监控读操作

EPOLLOUT
        The associated file is available for write(2) operations.
	    监控是否可写操作
			  

EPOLLRDHUP (since Linux 2.6.17)
        Stream socket peer closed connection, or shut down writing half of connection.  (This flag is espe‐cially useful for writing simple code to detect peer shutdown when using  Edge  Triggered  monitor‐ing.)
			  对方关闭连接,或者半关闭

EPOLLPRI
        There is urgent data available for read(2) operations.
	    有紧急数据可用于read(2)操作


EPOLLERR
        Error  condition  happened  on  the associated file descriptor.  epoll_wait(2) will always wait for this event; it is not necessary to set it in events.关联文件描述符发生错误条件。 Epoll_wait(2)将始终等待此事件; 没有必要在事件中设置它。

EPOLLHUP
        Hang up happened on the associated file descriptor.  epoll_wait(2) will always wait for this event; it is not necessary to set it in events.  Note that when reading from a channel such as a pipe or a stream socket, this event merely indicates that the peer closed its end of the channel.  Subsequent reads  from  the channel will return 0 (end of file) only after all outstanding data in the channel has been consumed.关联文件描述符上发生了挂起。 Epoll_wait(2)将始终等待此事件; 没有必要在事件中设置它。 请注意,当从通道(如管道或流套接字)读取数据时,此事件仅表明对等端关闭了通道的末端。 只有在通道中所有未完成的数据都被消耗掉之后,后续对通道的读取才会返回0(文件结束)。

EPOLLET
      Sets the Edge Triggered behavior for the associated file  descriptor.   The  default  behavior  for epoll  is  Level  Triggered.  See epoll(7) for more detailed information about Edge and Level Trig‐ gered event distribution architectures.
	  为关联的文件描述符设置边缘触发行为,默认是水平触发

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

QQ851301776

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值