erikzenker / inotify-cpp

A C++ interface for linux inotify
MIT License
136 stars 37 forks source link

multiple events at return of epoll_wait #59

Closed rasmus116 closed 5 years ago

rasmus116 commented 5 years ago

Theoretically, 10 events can return at the same time from epoll_wait.

auto nFdsReady = epoll_wait(mEpollFd, mEpollEvents, MAX_EPOLL_EVENTS, timeout);

In every iteration for these events data is reading into same memory address(eventBuffer.data()).

    for (auto n = 0; n < nFdsReady; ++n) {
        if (mEpollEvents[n].data.fd == mStopPipeFd[mPipeReadIdx]) {
            break;
        }

        length = read(mEpollEvents[n].data.fd, eventBuffer.data(), eventBuffer.size());
        if (length == -1) {
            mError = errno;
            if(mError == EINTR){
                break;
            }
        }
    }

Under these circumstances data of 'eventBuffer' is overwritten for each iteration of for loop.

That condition may be impossible for that project, but as a epoll_wait implementation it seems to be a problem.

erikzenker commented 5 years ago

Hi @rasmus116 , thank you very much for reporting that issue. That might be fixable easily by reducing the max epoll events to 1, right?

Adding more event buffers would also be a solution, but needs more changes for the first shot.

erikzenker commented 5 years ago

@rasmus116 ,I created a pull request for your issue. Would you like to make a review?

rasmus116 commented 5 years ago

It looks ok 👍 .

erikzenker commented 5 years ago

thx :+1: