最近在看windows網絡編程,因爲看的是翻譯版本,難免有錯誤,吐槽一下。如果你正好閱讀這本書,可以避免掉進某些我曾經掉進過去的坑裏面。翻譯錯誤,很可惡,但也很難免。
因爲我看的是掃描版本,先上一段圖片,內容在第五章102頁,講述select模式的使用。
從整體意圖來看,前面加小黑圓點的語句都是解析select某個參數的條件。再看看我圈出的四個紅框,我當時就很疑惑,一個是“如果”,一個是”假如“,作者這麼翻譯是因爲原文就是兩個不同的單詞,還是有別的原因?後面的“則連接就成功了”——注意“就“,這樣看來是陳述一件事情,並不是描述一個條件!同樣”連接嘗試就會失敗“也是陳述一件事情。我的迷惑在,你陳述一件事情,而且後面的”連接就會失敗“是一種已經發生的呢還是未發生的呢?不得其解。而且我們可以看到,這兩行字,除了我圈出來的前後兩處不一樣,中間的”正在對一個非阻塞連接調用進行處理“是相同的;這就奇怪了,同一種情況下,怎麼會出現“則連接就成功了”和”連接嘗試就會失敗“兩種完全相反的情況呢?
我斷定,這是一個錯誤的翻譯,起碼是一個不完全正確的翻譯。翻看原書,找出原文:
int select( int nfds, fd_set FAR * readfds, fd_set FAR * writefds, fd_set FAR * exceptfds, const struct timeval FAR * timeout );
The first parameter, nfds, is ignored and is included only for compatibility with Berkeley socket applications. You'll notice that there are three fd_set parameters: one for checking readability (readfds), one for writeability (writefds), and one for out-of-band data (exceptfds). Essentially, the fd_set data type represents a collection of sockets. The readfds set identifies sockets that meet one of the following conditions:
-
Data is available for reading.
-
Connection has been closed, reset, or terminated.
-
If listen has been called and a connection is pending, the accept function will succeed.
The writefds set identifies sockets in which one of the following is true:
-
Data can be sent.
-
If a non-blocking connect call is being processed, the connection has succeeded.
Finally, the exceptfds set identifies sockets in which one of the following is true:
-
If a non-blocking connect call is being processed, the connection attempt failed.
-
OOB data is available for reading.
可以看到了!if是一樣的,第一個沒有疑問,一個翻譯成”如果“一個翻譯成”假如“,作者的翻譯前後不一致!
後面的"the connection has successed"——完成時態唉!結合前面語境,這個是條件情況,明顯是已經成功!怎麼能翻譯成”則連接就成功了“呢?!應該翻譯成——如果一個非阻塞連接請求正在被處理,並且連接已經成功。
相應的"the connection attempt failed”,這裏也相應的是描述一個連接嘗試已經失敗的情況,不應該用“連接嘗試就會失敗”!應該翻譯成——如果一個非阻塞連接請求正在被處理,並且連接嘗試失敗。