I read the code in libevent epoll, here is the code:
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;
}
To my understanding, when EPOLLERR or EPOLLHUP happens, the connection should be closed. But in the above code, when EPOLLHUP|EPOLLERR encounters, the event mask is set to EV_READ | EV_WRITE. So my question is :
- What makes EPOLLERR and EPOLLHUP happen?
- When EPOLLERR and EPOLLHUP happen, what should the program do in the event handle function? And please explain the reason behind it in detail.
Thanks in advance!