0

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

本书勘误表页面并未将此列为错误:

http://www.unixnetworkprogramming.com/errata.html

4

1 回答 1

0

POSIX 将接口定义select() 为:

int select(int nfds, fd_set *restrict readfds,
       fd_set *restrict writefds, fd_set *restrict errorfds,
       struct timeval *restrict timeout);

select() 函数应等效于 pselect() 函数,但以下情况除外:

  • ...
  • 成功完成后,select() 函数可能会修改 timeout 参数指向的对象。

pselect函数接受一个const struct timespec * restrict timeout参数(POSIX 定义中的同一页)。

const本书引用的限定词是错误的。

于 2015-04-10T00:44:24.770 回答