Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);
我对maxevents参数有点困惑。假设我想编写一个可以处理多达 10k 个连接的服务器。那么我会将 maxevents定义为 10000,还是由于某种原因它应该更低?
Maxevents 只是struct epoll_events指向的数组的长度*events。
struct epoll_events
*events
如果内核在那个时候有超过这个数量的事件要提供给你的程序,它会发现它不应该因为你不期望在那个特定的 _wait 中返回这么多事件。
您可能需要为您的程序试验最佳大小。最佳尺寸甚至可能因架构而异。对于被轮询的少量文件描述符,您可以很容易地设置maxevents为文件数(并相应地调整events数组大小),但是同时需要注意所有文件的可能性很低,因此您可能可以使用一个较低的maxevents值。
maxevents
events