epoll_wait()中的maxevents参数和events数组的大小 [英] maxevents parameter in epoll_wait() and the events array size
问题描述
在epoll用法中,通常类似于以下内容:
struct epoll_event ev,events[20];
epfd=epoll_create(256);
。。。
nfds=epoll_wait(epfd,events,40,500);
有些文章说epoll_wait
中的maxevents
参数(即epoll_wait(epfd,events,40,500);
中的40
)不应超过epoll_create
(即256
)中的size参数.
我认为maxevents
参数不应超过ev, events[20]
中的20
,因为事件只能注册到20个事件元素;否则,如果有40个处于活动状态的套接字,那会发生什么?
顺便说一句,如果我注册了20个以上的套接字,并且有20个以上的活动事件(套接字),但是事件数组events[20]
只有20个事件,会发生什么?
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 (i.e. a smaller number might give you greater parallelism).
这篇关于epoll_wait()中的maxevents参数和events数组的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!