2 // generic/seq_packet_protocol.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_GENERIC_SEQ_PACKET_PROTOCOL_HPP
12 #define BOOST_ASIO_GENERIC_SEQ_PACKET_PROTOCOL_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
21 #include <boost/asio/basic_seq_packet_socket.hpp>
22 #include <boost/asio/detail/socket_types.hpp>
23 #include <boost/asio/detail/throw_exception.hpp>
24 #include <boost/asio/generic/basic_endpoint.hpp>
26 #include <boost/asio/detail/push_options.hpp>
32 /// Encapsulates the flags needed for a generic sequenced packet socket.
34 * The boost::asio::generic::seq_packet_protocol class contains flags necessary
35 * for seq_packet-oriented sockets of any address family and protocol.
38 * Constructing using a native address family and socket protocol:
39 * @code seq_packet_protocol p(AF_INET, IPPROTO_SCTP); @endcode
42 * @e Distinct @e objects: Safe.@n
43 * @e Shared @e objects: Safe.
48 class seq_packet_protocol
51 /// Construct a protocol object for a specific address family and protocol.
52 seq_packet_protocol(int address_family, int socket_protocol)
53 : family_(address_family),
54 protocol_(socket_protocol)
58 /// Construct a generic protocol object from a specific protocol.
60 * @throws @c bad_cast Thrown if the source protocol is not based around
63 template <typename Protocol>
64 seq_packet_protocol(const Protocol& source_protocol)
65 : family_(source_protocol.family()),
66 protocol_(source_protocol.protocol())
68 if (source_protocol.type() != type())
71 boost::asio::detail::throw_exception(ex);
75 /// Obtain an identifier for the type of the protocol.
78 return BOOST_ASIO_OS_DEF(SOCK_SEQPACKET);
81 /// Obtain an identifier for the protocol.
87 /// Obtain an identifier for the protocol family.
93 /// Compare two protocols for equality.
94 friend bool operator==(const seq_packet_protocol& p1,
95 const seq_packet_protocol& p2)
97 return p1.family_ == p2.family_ && p1.protocol_ == p2.protocol_;
100 /// Compare two protocols for inequality.
101 friend bool operator!=(const seq_packet_protocol& p1,
102 const seq_packet_protocol& p2)
107 /// The type of an endpoint.
108 typedef basic_endpoint<seq_packet_protocol> endpoint;
110 /// The generic socket type.
111 typedef basic_seq_packet_socket<seq_packet_protocol> socket;
118 } // namespace generic
122 #include <boost/asio/detail/pop_options.hpp>
124 #endif // BOOST_ASIO_GENERIC_SEQ_PACKET_PROTOCOL_HPP