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: