开发者社区> 问答> 正文

AcceptEx的第3个参数:lpOutputBuffer,应该怎么设置?

在IOCP模型编程中,因为采用AcceptEx异步接受连接,所以要一次性提交许多AcceptEx,其中第3个参数lpOutputBuffer,看了msdn是用来存放客户端和服务端地址信息等数据的。 那么按道理说,一个AcceptEx对应着专属于它的一个buffer,但是看到msdn有段Remark是这样写的:

Using a single buffer improves performance. When using AcceptEx, the GetAcceptExSockaddrs function must be called to parse the buffer into its three distinct parts (data, local socket address, and remote socket address). On Windows XP and later, once the AcceptEx function completes and the SOUPDATEACCEPT_CONTEXT option is set on the accepted socket, the local address associated with the accepted socket can also be retrieved using the getsockname function. Likewise, the remote address associated with the accepted socket can be retrieved using the getpeername function.
无法理解加粗那句话的意思,是指用一个buffer(全局变量)来应付所有的AcceptEx以提高性能吗?

展开
收起
a123456678 2016-03-09 18:18:09 2355 0
1 条回答
写回答
取消 提交回答
  • 在你引用的这段话之前的一句话如下:

    A single output buffer receives the data, the local socket address (the server), and the remote socket address (the client).
    结合上下文就明了了。
    这分明说的是用一个buffer来同时接收data,local socket address和remote socket address,而不用分为三个buffer。通过这样的方法来提高性能。
    也正是因为这样一个机制,所以接下来才说需要调用GetAcceptExSockaddrs来解析这三块不同的数据。

    2019-07-17 18:56:29
    赞同 展开评论 打赏
问答分类:
问答地址:
相关产品:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载