Boost Asio type to use for both unix-socket and tcp socket

后端 未结 1 1553
囚心锁ツ
囚心锁ツ 2021-02-10 16:46

We have a boost asio based networking code, which connects to a remote side. The local side could be either a tcp4 socket or a unix socket.

Is there a typename to use th

相关标签:
1条回答
  • 2021-02-10 17:27

    Actually, there's a dedicated ip::tcp::socket type for tcp sockets. As for generic::stream_protocol::socket, it is the universal stream socket type that accepts socket protocol and family in run-time, so you can use it for the both types you need:

    generic::stream_protocol::socket ipc(io_, generic::stream_protocol(AF_UNIX, 0));
    generic::stream_protocol::socket tcp(io_, generic::stream_protocol(AF_INET, IPPROTO_TCP));
    
    0 讨论(0)
提交回复
热议问题