visual studio - C++ Boost.ASIO: passing accepted TCP connection from one opened socket to another using Windows APIs ( while works with Linux APIs)? -
I was trying to re-specify an acceptable connection using Boost.ASIO and Windows API. Contains names added and namespaces, so now it is consistent - just copy and paste and here you can go ... "Parameter is wrong" was the exception to the same location code poster = (Here is the code : Add
# & lt; iostream & gt; # & lt; promotion / asio.hpp & gt; using namespace STD; _WIN32 #include "windows.h "Using name space boost :: asio :: IP #endif #ifdef; integer main () {int m_nPort = 12345, boost :: asio :: io_servi ce io_service; TCP :: acceptor acceptor (io_service, TCP :: endpoint (TCP :: v4 (), m_nPort)); court & lt; & lt; "Waiting connection ... to"; & lt; endl; TCP :: socket (io_service); acceptor.accept (socket); & lt court & lt; & lt; "connection accepted" & lt; & lt; endl; #ifdef _WIN32 WSAPROTOCOL_INFO exemplary; WSADuplicateSocket (socket .native (), GetCurrentProcessId (), & amp; pI); socket socketDup = WSASocket (pi.iAddressFamily / * AF_INET * /, pi.iSocketType / * SOCK_STREAM * /, pi.iProtocol / * IPPROTO_TCP * /, & amp; PE, 0, 0); Four Sitest [] = "I can use my duplicate socket via WINP! \ R \ n"; Int nRet = s end (socketedup, essex, stran (estext), 0); #alse // linux int socketdepp = deep (socket.NET ()); // test on Linux, works! Try #endif {tcp :: socket s (io_service); S.assign (tcp :: v4 (), SocketDupp); // It throws an exception under Windows / I can not use s.send (boost :: asio :: buffer ("not working \ r \ n") to promote my socket; Cout & lt; & Lt; "We do not get here = (!" & Lt; & lt; endl;} catch (exception & amp; e) {cerr & lt; e.what () & lt; In general and I do not really see what is wrong, how it should not be decided.
And this is how we will
Maybe I could not find any problem.
Update: Just test code on Linux - works perfectly, no error. Then this windows Try to use the code snippet attached to the document:
socketDup = WSASocket (FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, & amp; pi, 0, WSA_FLAG_OVERLAPPED);
Okay, I have figured out through Boost Code, and it fails to attempt to associate the S with the I / O completion port oaket because that socket is already full port Of Is connected with.
says:
This call is not the best either handle or Duplikethandl function to share I / O handling file associated with full port. Generates operational completion reports executed with such duplicate handles. Careful consideration is advised.
IOCP problem is related to, knowing this, I set) before including any boost headers (
#define BOOST_ASIO_DISABLE_IOCP 1 And everything works fine.
Local output:
Waiting for connection ... The connection has been accepted We are not here! = ( Remote output:
I can use my duplicate socket via WinApi! Not working
Comments
Post a Comment