c - 在 c 中调用 select 后超时是否改变?

标签 c linux sockets select

在我的套接字编程作业中,我进行了如下选择调用:

select(s+1, &rfds, (fd_set *)0, (fd_set *)0,&tv)

其中 tv 的类型为 struct timeval

我阅读了 select 的手册页,它说:

On Linux, the function select modifies timeout to reflect the amount of time not slept; most other implementations do not do this. This causes problems both when Linux code which reads timeout is ported to other operating systems, and when code is ported to Linux that reuses a struct timeval for multiple selects in a loop without reinitializing it. Consider timeout to be undefined after select returns.

这是否意味着我的 tv 变量会在调用 select 之后改变? (我正在使用 Ubuntu)

最佳答案

是的,确实如此。为了可移植性,您应该在每次调用 select 之前重新初始化它。

关于c - 在 c 中调用 select 后超时是否改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4407012/

相关文章:

c - 为什么这不会打印?

c - :1: error: expected ‘=’ , ‘,’、 ‘;’、 ‘asm’ 或 ‘__attribute__’ 位于 ‘{’ token 之前

linux - Bash - 提取给定关键字的行 block

sockets - 套接字描述符泄漏 - lsof 无法识别协议(protocol)?

c - TCP多客户端服务器程序

c - 关于 pipeline、fork 和 if 语句的初学者问题

c - 如何使用 arm-none-eabi-gcc + cmake 设置 cmocka 示例?

在 C 中检查环境变量是否为空

linux - 创建一个别名以进行适用于任何目录的相同 ant 命令调用

linux - 如何将一些文件(可能像/home/eric/libtest0.1.so)添加到 Yocto rootfs lib 文件夹(/lib)?