在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以提高性能吗?
這個問題沒有上下文就費解了。
在你引用的這段話之前的一句話如下:
結合上下文就明了了。
這分明說的是用一個buffer來同時接收data,local socket address和remote socket address,而不用分為三個buffer。通過這樣的方法來提高性能。
也正是因為這樣一個機製,所以接下來才說需要調用
GetAcceptExSockaddrs
來解析這三塊不同的數據。