I'm trying to implement my own apache server, and I was coding the socket server with epoll, and the events
array needs a determinated numbers of elements, but how should I define that number if I don't know the total amount of request that the application would have.
struct epoll_event events[What would be the size?];
I don't have tried anything yet. I've searched some info but apache does not seem to use epoll, it has its own implementation (or that is what I've understood).
You determine this in exact same fashion you determine the size of the buffer for reading a file of unknown length: you use a fixed-size buffer, then read, and then continue reading until reaching the end of the file.
The same exact principle applies here. You figure out the size of your event buffer, then start reading events, repeatedly.
There is no universal formula that works for every application that uses epoll_wait
. This is something that you will first have to make an educated guess, and then carefully monitor the actual results, and perhaps fine-tune the size of your event buffer, if needed.
epoll_wait
will, depending on its parameters, block until there's at least one event to read. Then in any event (pardon the pun) proceed and read up to the number of events that was specified.
If there are more events available, the remaining events remain unread and then will be read by the next call to epoll_wait
.