I suggest to keep it simple:
#include <boost/asio.hpp>
int main() {
boost::asio::io_service io_service;
using boost::asio::local::stream_protocol;
stream_protocol::socket s(io_service);
s.connect("/tmp/socket");
}
No doubt you can go more lowlevel, but I'm not sure when you'd need that.
UPDATE 2 In Boost 1.82.0, Asio 1.27.0 added local::seq_packet_protocol
UPDATE Mimicking the pre-defined stream_protocol
, here's how to define seqpacket_protocol
:
Live On Coliru
namespace SeqPacket {
using namespace boost::asio::local;
struct seqpacket_protocol
{
int type() const { return IPPROTO_SCTP; }
int protocol() const { return 0; }
int family() const { return AF_UNIX; }
typedef basic_endpoint<seqpacket_protocol> endpoint;
typedef boost::asio::basic_stream_socket<seqpacket_protocol> socket;
typedef boost::asio::basic_socket_acceptor<seqpacket_protocol> acceptor;
#if !defined(BOOST_ASIO_NO_IOSTREAM)
/// The UNIX domain iostream type.
typedef boost::asio::basic_socket_iostream<seqpacket_protocol> iostream;
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
};
}
Just use it in the same pattern:
int main() {
boost::asio::io_service io_service;
using SeqPacket::seqpacket_protocol;
seqpacket_protocol::socket s(io_service);
s.connect("socket");
}