加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 如何处理EPOLLERR和EPOLLHUP?

发布时间:2020-12-13 22:56:01 所属栏目:Linux 来源:网络整理
导读:我在libevent epoll中阅读了代码,这里是代码: if (what (EPOLLHUP|EPOLLERR)) { ev = EV_READ | EV_WRITE; } else { if (what EPOLLIN) ev |= EV_READ; if (what EPOLLOUT) ev |= EV_WRITE; if (what EPOLLRDHUP) ev |= EV_CLOSED; } 据我所知,当EPOLLERR或
我在libevent epoll中阅读了代码,这里是代码:

if (what & (EPOLLHUP|EPOLLERR)) {
            ev = EV_READ | EV_WRITE;
        } else {
            if (what & EPOLLIN)
                ev |= EV_READ;
            if (what & EPOLLOUT)
                ev |= EV_WRITE;
            if (what & EPOLLRDHUP)
                ev |= EV_CLOSED;
        }

据我所知,当EPOLLERR或EPOLLHUP发生时,应该关闭连接.但是在上面的代码中,当EPOLLHUP | EPOLLERR遇到时,事件掩码被设置为EV_READ | EV_WRITE.所以我的问题是:

>是什么让EPOLLERR和EPOLLHUP发生?
>当EPOLLERR和EPOLLHUP发生时,程序应该在事件处理函数中做什么?请详细解释其背后的原因.

提前致谢!

解决方法

What makes EPOLLERR and EPOLLHUP happen?

男人epoll_ctl

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.

   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.

When EPOLLERR and EPOLLHUP happen,what should the program do in the
event handle function?

随着libevent通过事件EV_READ |在这种情况下,EV_WRITE,回调函数调用e. G. recv(),当对等体执行有序关闭(EPOLLHUP)时可能返回0,如果发生错误则返回-1(EPOLLERR);然后程序可能会清理连接,如果它是客户端,可能会重新建立连接.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读