进行 select 调用时,"socket + 1" 实现了什么? unix/c++
What is "socket + 1" achieving when making a select call? unix/c++
我正在基于此 https://linux.m2osw.com/c-implementation-udp-clientserver 实现一个 udp 侦听服务器。我注意到在建立超时接收器时,作者在进行 select 调用时包含了 "f_socket+1"。我想知道这到底在做什么?任何解释都有帮助,谢谢!
上面的函数摘录link:
FD_ZERO(&s);
FD_SET(f_socket, &s);
struct timeval timeout;
timeout.tv_sec = max_wait_ms / 1000;
timeout.tv_usec = (max_wait_ms % 1000) * 1000;
int retval = select(f_socket + 1, &s, &s, &s, &timeout);
见https://pubs.opengroup.org/onlinepubs/007908799/xsh/select.html
The nfds argument specifies the range of file descriptors to be tested. The select() function tests file descriptors in the range of 0 to nfds-1.
因此,该参数应设置为比您要监视的最大文件描述符大 1。
我正在基于此 https://linux.m2osw.com/c-implementation-udp-clientserver 实现一个 udp 侦听服务器。我注意到在建立超时接收器时,作者在进行 select 调用时包含了 "f_socket+1"。我想知道这到底在做什么?任何解释都有帮助,谢谢!
上面的函数摘录link:
FD_ZERO(&s);
FD_SET(f_socket, &s);
struct timeval timeout;
timeout.tv_sec = max_wait_ms / 1000;
timeout.tv_usec = (max_wait_ms % 1000) * 1000;
int retval = select(f_socket + 1, &s, &s, &s, &timeout);
见https://pubs.opengroup.org/onlinepubs/007908799/xsh/select.html
The nfds argument specifies the range of file descriptors to be tested. The select() function tests file descriptors in the range of 0 to nfds-1.
因此,该参数应设置为比您要监视的最大文件描述符大 1。