函数原型 int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
引用解释:
根据POSIX标准,
The nfds argument specifies the range of descriptors to be tested. The first nfds descriptors shall be checked in each set; that is, the descriptors from zero through nfds-1 in the descriptor sets shall be examined.
个人理解:
系统内部用bitmask描述fd set,fd number 从0开始,fd = x 的句柄描述符在 bit mask中的位置是第x+1,所以select需要monitor前x+1个句柄对应的device,所以ndfs = x+1
阅读(2994) | 评论(0) | 转发(0) |