How to create a Boost.Asio socket from a native socket?

前端 未结 1 1867
我在风中等你
我在风中等你 2020-12-30 09:29

I am merely trying to create a boost ip::tcp::socket from an existing native socket. In the assign function, the first parameter must be a \"protocol_type\" and

1条回答
  •  执念已碎
    2020-12-30 09:51

    "Native type" is just the socket handle, in this case the int stored in "socket".

    "Protocol type" is the the protocol. For a TCP over standard IP using stream socket, this would be the return value from boost::asio::ip::tcp::v4(). Substitute as appropriate for datagram sockets, IPv6, etc.

    So:

    s.assign(boost::asio::ip::tcp::v4(), socket);
    

    Adjusted as appropriate for what you're trying to do.

    0 讨论(0)
提交回复
热议问题