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

We have asio-based network code that connects to the remote side. The local side can be either a tcp4 socket or a unix socket.

Is it possible to use a type name that could contain both types of raise sockets? (for example, something like a base class for both?). Currently using our code boost::asio::generic::stream_protocol::socketfor tcp socket and boost::asio::local::stream_protocol::socketfor unix socket.

+4
source share
1 answer

Actually there is a special type ip::tcp::socketfor tcp sockets. As for generic::stream_protocol::socket, this is a universal type of stream socket that accepts the socket protocol and its family at run time, so you can use it for both types that 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));
+5
source

All Articles