IOCP和.net Socket Class

.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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值