c++ - AcceptEx的第3个参数:lpOutputBuffer,应该怎么设置?
阿神
阿神 2017-04-17 11:09:25
[C++讨论组]

在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以提高性能吗?

阿神
阿神

闭关修行中......

全部回复(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来解析这三块不同的数据。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号