- 論壇徽章:
- 0
|
本帖最后由 himrpei 于 2014-10-29 22:11 編輯
疑惑一:用 socket 系統(tǒng)調用創(chuàng)建的 socket 默認就是阻塞模式吧?
疑惑二:
man sendto 看到關于“阻塞”的描述如下:
When the message does not fit into the send buffer of the socket, send() normally blocks, unless the socket has been placed in nonblocking I/O mode. In nonblocking mode it would fail with the error EAGAIN or EWOULDBLOCK in this case.
根據(jù)如上描述,我這樣做:
用 setsockopt 將創(chuàng)建的 socket 的 send buffer 設置為一個較小的值,比如 2050 。然后調用 sendto 通過這個 socket 發(fā)數(shù)據(jù),數(shù)據(jù)的大小大于 send buffer 的值,比如 5000 。
本來想著,如果 socket 是阻塞模式,調用 sendto 進程應該卡在那不動才對。誰知程序直接報錯返回,將 errno 設置為:ENOBUFS 。
man sendto 關于 ENOBUFS 的描述為:
The output queue for a network interface was full. This generally indicates that the interface has stopped sending, but may be caused by transient congestion. (Normally, this does not occur in Linux. Packets are just silently dropped when a device queue overflows.)
我的疑惑是,對于 sendto 來說,阻塞的含義到底是什么? “The output queue for a network interface was full” 時為什么沒有發(fā)生阻塞,在 socket 設為阻塞模式的時候?
求哥哥、姐姐、大神、大師們解答下我的疑惑。不勝感激! |
|