NCindy

.net平台上的高性能网络程序开发框架

IOCP和.net Socket Class

众所周知,IOCP是在Windows平台实现高性能、高扩展性的Socket服务器的一个重要手段。对于.net这个平台,是否还能使用IOCP呢?答案是肯定的。
那如何使用IOCP呢?本文虽然没有给出具体的实现,但是给出的一些参考文档,做为实现的指引。
.net的Socket类在使用异步IO模型时会自动使用Windows的完成端口内核对象,在Windows网络编程第二版中是这样描述的:

 The asynchronous model in .NET sockets is the best way to manage I/O from one or more sockets. It is the most efficient model of the three because its design is similar to the I/O completion ports model (described in Chapter 5) and on Windows NT–based systems it will use the completion port I/O model internally. Because of this, you can potentially develop a high-performance, scalable Winsock server in C# and even possibly in Visual Basic. For a complete discussion of how to develop a high-performance, scalable Winsock application, see Chapter 6.

Socket类型在.net 2.0版本中更加增强了,一个显著的区别是,.net 2.0中的Socket可以使用DuplicateAndClose来对Socket进行持久化。这个方法的Remarks是这么写的:

If the process creating the socket uses asynchronous methods (BeginReceive or BeginSend), the process must first set the UseOnlyOverlappedIO property to true; otherwise, the socket is bound to the completion port of the creating process, which may cause an ArgumentNullException to be thrown on the target process.

因为持久化IOCP内核对象是没有意义的,或者说无法通过持久化信息恢复完成端口的状态,所以Socket类型拥有了一个属性,UseOnlyOverlappedIO ,这个属性的Remarks是这么写的:

Set this property to true for a Socket you intend to call DuplicateAndClose. Otherwise, the Framework may assign a completion port to the socket, which would prohibit the use of DuplicateAndClose.



iceboundrock 2006-08-10 21:47 发表评论

posted on 2006-08-10 21:47  iceboundrock  阅读(1806)  评论(0编辑  收藏  举报

导航