A simple test on epoll_wait return values

Source: Internet
Author: User

A simple test on epoll_wait return values

A simple test on epoll_wait return values

Void test (int epollfd)
{
Struct epoll_event events [MAX_EVENT_NUMBER];
Int number;

While (1)
{
Number = epoll_wait (epollfd, events, MAX_EVENT_NUMBER,-1 );
Printf ("number: % 2d \ n", number );
For (I = 0; I <number; I ++)
{
Sockfd = events [I]. data. fd;

If (sockfd = listenfd)
{/* Publish a user */

}
Else if (events [I]. events & EPOLLIN)
{/* Data readable */

}
Else if (events [I]. events & EPOLLOUT)
{/* Data writable */

}
Else
{/* Error */

}
}
}
}

The test shows that the returned value number of epoll_wait is not greater than that of MAX_EVENT_NUMBER.

During the test, the number of connected clients is much greater than MAX_EVENT_NUMBER. It can be inferred that epoll_wait () returns the number of active clients each time, add the active client information to events [MAX_EVENT_NUMBER] each time.

It can be seen that when the number of active clients is the same, the greater events [MAX_EVENT_NUMBER], the fewer epoll_wait () function executions, but the larger events [MAX_EVENT_NUMBER], the more storage resources are consumed.

Therefore, the choice of MAX_EVENT_NUMBER should strike a balance between efficiency and resources.

This article permanently updates the link address:

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.