Personal Understanding of epollhup and personal understanding of epollhup

Source: Internet
Author: User
Tags socket connect

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.