我阅读了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。所以我的问题是:
提前致谢!
最佳答案
man 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.
在这种情况下,当libevent传递事件
EV_READ | EV_WRITE
时,回调函数将调用e。 G。 recv()
,当对等方执行有序关闭(EPOLLHUP)时可能返回0,如果发生错误则返回-1(EPOLLERR);然后,程序可能会清理连接,如果是客户端,则可能会重新建立连接。