C++ Boost.ASIO: passing accepted TCP connection from one opened socket to another using Windows APIs ( while works with Linux APIs)?

倾然丶 夕夏残阳落幕 提交于 2019-12-01 00:47:43

Try using the code snippet attached to the WSASocket documentation:

socketDup = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, &pi, 0, WSA_FLAG_OVERLAPPED);


Ok, I traced through the Boost code, and it fails trying to associate the socket with the I/O completion port. That's because the socket is already associated to a completion port.

The MSDN docs say:

It is best not to share a file handle associated with an I/O completion port by using either handle inheritance or a call to the DuplicateHandle function. Operations performed with such duplicate handles generate completion notifications. Careful consideration is advised.

Knowing that IOCP is related to the problem, I set (before including any boost headers)

#define BOOST_ASIO_DISABLE_IOCP 1

and everything works fine.

local output:

Waiting for connection...
connection accepted
We do not get here!=(

remote output:

I can use my duplicated socket via WinApi!
Not work
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!