[英]What type of Visual Studio c++ project should i select for making basic unix apps
[英]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”。 我想知道这到底在做什么? 任何有用的解释,谢谢!
function 摘自上述链接:
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
nfds参数指定要测试的文件描述符的范围。 select() function 测试 0 到nfds -1 范围内的文件描述符。
因此,该参数应设置为大于您要监视的最大文件描述符的 1。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.