简体   繁体   中英

epoll_wait() events buffer reset

The second parameter of epoll_wait() is a buffer of size = sizeof (struct epoll_event) * total number events(file descriptor) caller is expecting (or monitoring). This buffer is always initialized to zero before passing to epoll_wait() for the first time.

For the following code snippet

memset(&events[0], 0, maxEvents * sizeof (struct epoll_event))
do
{
    result = epoll_wait(epoll_fd, &events[0], maxEvents, timeout)
    if (result)
    {
        //process events
    }
} while (1)

Is it good to reset events buffer after processing the events every time epoll_wait() returns?

No.

A much better approach is to fix the bug you have in the code. result from epoll_wait is not a boolean. It is an integere specifying how many buffers were filled in the supplied buffers list.

If you make sure to read only those, you will not need to zero initialize the buffers at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM