【发布时间】:2015-04-10 00:26:10
【问题描述】:
select(2) 系统调用在 Stevens、Fenner 和 Rudoff 的 Unix Network Programming (2003) 第 6.3 章中定义如下:
#include <sys/select.h>
#include <sys/time.h>
int select(int maxfdp1, fd_set *readset, fd_set *writeset,
fd_set *exceptset, const struct timeval *timeout);
但是现代 Unix 系统(例如 FreeBSD、OpenBSD、NetBSD、Linux,甚至 POSIX[1] 标准)都没有这样定义系统调用。但是,书中指出“POSIX 指定了 const 限定符”。难道是书上的错误?还是因为历史原因?不过,所有系统都将 pselect(2) 定义为具有恒定的超时参数。
http://pubs.opengroup.org/onlinepubs/009695399/functions/pselect.html
图书勘误页并未将此列为错误:
【问题讨论】:
-
这是书中的错误:
Upon successful completion, the select() function may modify the object pointed to by the timeout argument.SUSv2 说了类似的话,是从 1997 年开始的。 -
恕我直言,这是否是一个错误值得商榷。 POSIX 标准是模棱两可的,因为它说超时值“可以”被修改。因此,任何实现都可以选择不修改它并将其定义为 const。甚至 Linux select 手册页也暗示了这种含糊之处:“在 Linux 上,select() 修改超时以反映未睡眠的时间量;大多数其他实现都没有这样做。(POSIX.1-2001 允许任何一种行为。).. . 考虑在 select() 返回后未定义超时。"
-
感谢您的帮助。我已将此错误报告给作者。
标签: c unix standards portability multiplexing