Archive for 2016年1月
select函数第一个参数
2016-01-17
留下评论
初次接触select,对第一个参数nfds为什么是监听的最大描述符加一很不理解,看了man手册之后明白了,里面有这么一句话:
The first nfds descriptors are checked in each set; i.e., the descriptors from 0 through nfds-1 in the descriptor sets are examined. (Example: If you have set two file descriptors “4” and “17”, nfds should not be “2”, but rather “17 + 1” or “18”.)
因为fd_set是一个数组,它的下标即为描述符,如果某个描述符需要监听,则把对应下标的值置为1。同时参考上面那段英文,就不难理解为什么是最大描述符加一了。
最后说一句:man真是个好东西!
分类:编程