select only checks fds till 255 not till FD_SETSIZE
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: select on fds higher then 255 do not check if the fd is open. Here is my example code: #include <stdio.h> #include <errno.h> #include <unistd.h> #include <sys/select.h> int main() { fd_set set; for(int i = 5;i<FD_SETSIZE;i++) { printf("--> i is %d\n", i); FD_ZERO(&set); FD_SET(i, &set); close(i); int retval = select(FD_SETSIZE, &set, NULL, NULL, NULL); if(-1 == retval) { perror("select"); } } } This results in: --> i is 5 select: Bad file descriptor ... --> i is 255 select: Bad file descriptor --> i is 256 Then the application blocks. Why