简体   繁体   中英

maxevents parameter in epoll_wait() and the events array size

In epoll usage, it is usually like the following:

struct epoll_event ev,events[20];
epfd=epoll_create(256);
。。。
nfds=epoll_wait(epfd,events,40,500);

Some articles are saying that the maxevents parameter in epoll_wait (namely the 40 in epoll_wait(epfd,events,40,500); ) should not exceed the size parameter in epoll_create (namely the 256 ).

I think the maxevents parameter should not exceed 20 in ev, events[20] , because events can only be registered to 20 events elements; otherwise, if there are 40 sockets which are active, then what will happen?

BTW, if I register more than 20 sockets and there are more than 20 active events(sockets), but the events array events[20] has only 20 events, what will happen?

At any single call of epoll_wait you'll at most receive as many events as you have room for, but of course events don't get lost if there are more than that queued up -- you'll simply get them at a later call. Since you'll be calling epoll_wait in a loop anyway, that shouldn't be an issue at all.

The one interesting consideration I can think of is when you have multiple threads read from the same epoll-fd concurrently. In that case the size of your event array determines how many events get handled by a single thread (ie a smaller number might give you greater parallelism).

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