Personal Understanding of epollhup and personal understanding of epollhup
1. Cause
Due to the recent test of the asynchronous connect function, it is found that the epollhup event will continuously occur when a socket is added to the epoll listening queue in advance.
2. Example
........
IEpoll = epoll_create (1 );
IFd = socket (AF_INET, SOCK_STREAM, 0 );
StEvent. events = EPOLL_IN;
StEvent. data. u32 = iFd;
Epoll_ctl (iEpoll, EPOLL_CTL_ADD, iFd, & stEvent );
I = epoll_wait (iEpoll, astEvent, 1,-1 );
...................
3. debugging
After the tcp socket is created, no chain or listen has been created. This indicates that no event is reported in this case. Therefore, adding such a socket to the listen queue is incorrect, however, epoll_ctl is successfully added, which is confusing. even if the socket connect or listen is used in subsequent operations, the hup event is reported because the previous event is not processed due to the horizontal triggering event.
4. Solution
The above analysis shows that adding a socket that cannot trigger this event to epoll will result in the reporting of the hup event. Therefore, when receiving this event, one way is to remove the socket from the epoll listening queue, another method is to add the socket to epoll after the connect operation or after the listen operation.