- 论坛徽章:
- 0
|
回复 #12 PHizing 的帖子
这节是说non-block I/O,不是说 non-block select。目标不是select那不阻塞(整个程序就是读写,没数据来不等待还能干吗?),而是及时(不阻塞)地读写东西。所以socket和std in/out 都是non-block的。
- 10 val = Fcntl(sockfd, F_GETFL, 0);
- 11 Fcntl(sockfd, F_SETFL, val | O_NONBLOCK);
- 12 val = Fcntl(STDIN_FILENO, F_GETFL, 0);
- 13 Fcntl(STDIN_FILENO, F_SETFL, val | O_NONBLOCK);
- 14 val = Fcntl(STDOUT_FILENO, F_GETFL, 0);
- 15 Fcntl(STDOUT_FILENO, F_SETFL, val | O_NONBLOCK);
复制代码
其实作者已经把意思讲得很清楚了
For example, if a line is available on standard input, we read it with read and then send it to the server with writen. But the call to writen can block if the socket send buffer is full. While we are blocked in the call to writen, data could be available for reading from the socket receive buffer. |
|