《UNIX网络编程》勘误:6.3节 select描述

《UNIX网络编程》卷一(第三版):套接字联网API 6.3节

中文版128页(人民邮电出版社 2010年7月第一版)

英文版162页


旷世经典UNP也难免有错,实在是明珠蒙尘。不过也无伤大雅。

6.3节介绍了select。其中在描述select函数参数的时候,有处错误,部分原文摘录如下:

#include 
#include 
int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
const struct timeval *timeout);

Returns: positive count of ready descriptors, 0 on timeout, −1 on error

The const qualifier on the timeout argument means it is not modified by select on return.

中文版翻译:

timeout参数的const限定词表示它在函数返回时不会被select修改。

翻译本身没有问题。但是问题在于原文就是不对的。select的timeout这个参数是不带const限定词的。你传给const的进去反而会报错的!

select的POSIX官方定义如下:

pselect​pubs.opengroup.org

另外Google一下可以发现国外也有人讨论过,可以证明这个确实是作者的mistake。

附StackOverflow的讨论,以及这本书的官方勘误list(未包含本文内容):

  • select-with-const-timeout-parameter
  • errata

你可能感兴趣的:(《UNIX网络编程》勘误:6.3节 select描述)