- 论坛徽章:
- 0
|
原帖由 benjiam 于 2008-6-8 15:09 发表 ![]()
??? 好像不对吧。这个时候应该是blocking 方式才能立刻知道结果。
如果是non-block 的话, 应该是立刻返回,而不知道是否真正完成,由后面的事件来通知完成。
如果是send 的话, 我认为 是否block 的问题并不是很多, 而recv 的是否block 才是提高系统响应的关键。
不知道有没看过 <Network Programming for Microsoft Windows, Second Edition> 这本书?
里面有一段
Maximizing Connections
Maximizing the number of concurrent client connections is the more difficult of the two strategies. Handling the I/O on each connection becomes difficult. A server cannot simply post one or more sends or receives on each connection because the amount of memory (both in terms of locked pages and non-paged pool) is great. In this scenario, the server is interested in handling many connections at the expense of throughput on each connection. An example of this would be an instant messenger server. The server would handle many thousands of connections but would need to send or receive only a small number of bytes at a time.
For this strategy, the server does not necessarily want to post an overlapped receive on each connection because this would involve locking many pages for each of the receive buffers. Instead, the server can post an overlapped zero-byte receive. Once the receive completes, the server would perform a non-blocking receive until WSAEWOUDLBLOCK is returned. This allows the server to immediately receive all buffered data received on that connection. Because this model is geared toward clients that send data intermittently, it minimizes the number of locked pages but still allows processing of data on each connection.
通常用 epoll 的时候,也是用 non-blocking 的方式的吧? non-blocking 是可以立即知道操作结果的,和 blocking 的差别在于当没有数据可读的时候,non-blocking 会返回 -1 ,并设置 errno 为 EWOUDLBLOCK ,blocking 则会阻塞调用者。
[ 本帖最后由 iunknown 于 2008-6-8 21:10 编辑 ] |
|