在我的套接字编程作业中,我进行了如下选择调用:
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/