在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以提高性能吗?
在你引用的这段话之前的一句话如下:
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来解析这三块不同的数据。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。