《UNIX網(wǎng)絡(luò)編程》卷一(第三版):套接字聯(lián)網(wǎng)API 6.3節(jié)
中文版128頁(人民郵電出版社 2010年7月第一版)
英文版162頁
曠世經(jīng)典UNP也難免有錯,實(shí)在是明珠蒙塵。不過也無傷大雅。
6.3節(jié)介紹了select。其中在描述select函數(shù)參數(shù)的時候,有處錯誤,部分原文摘錄如下:
#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);
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參數(shù)的const限定詞表示它在函數(shù)返回時不會被select修改。
翻譯本身沒有問題。但是問題在于原文就是不對的。select的timeout這個參數(shù)是不帶const限定詞的。你傳給const的進(jìn)去反而會報(bào)錯的!
select的POSIX官方定義如下:
另外Google一下可以發(fā)現(xiàn)國外也有人討論過,可以證明這個確實(shí)是作者的mistake。
附StackOverflow的討論,以及這本書的官方勘誤list(未包含本文內(nèi)容):