Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:53

0001 //
0002 // generic/seq_packet_protocol.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_GENERIC_SEQ_PACKET_PROTOCOL_HPP
0012 #define BOOST_ASIO_GENERIC_SEQ_PACKET_PROTOCOL_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 
0020 #include <typeinfo>
0021 #include <boost/asio/basic_seq_packet_socket.hpp>
0022 #include <boost/asio/detail/socket_types.hpp>
0023 #include <boost/asio/detail/throw_exception.hpp>
0024 #include <boost/asio/generic/basic_endpoint.hpp>
0025 
0026 #include <boost/asio/detail/push_options.hpp>
0027 
0028 namespace boost {
0029 namespace asio {
0030 namespace generic {
0031 
0032 /// Encapsulates the flags needed for a generic sequenced packet socket.
0033 /**
0034  * The boost::asio::generic::seq_packet_protocol class contains flags necessary
0035  * for seq_packet-oriented sockets of any address family and protocol.
0036  *
0037  * @par Examples
0038  * Constructing using a native address family and socket protocol:
0039  * @code seq_packet_protocol p(AF_INET, IPPROTO_SCTP); @endcode
0040  *
0041  * @par Thread Safety
0042  * @e Distinct @e objects: Safe.@n
0043  * @e Shared @e objects: Safe.
0044  *
0045  * @par Concepts:
0046  * Protocol.
0047  */
0048 class seq_packet_protocol
0049 {
0050 public:
0051   /// Construct a protocol object for a specific address family and protocol.
0052   seq_packet_protocol(int address_family, int socket_protocol)
0053     : family_(address_family),
0054       protocol_(socket_protocol)
0055   {
0056   }
0057 
0058   /// Construct a generic protocol object from a specific protocol.
0059   /**
0060    * @throws @c bad_cast Thrown if the source protocol is not based around
0061    * sequenced packets.
0062    */
0063   template <typename Protocol>
0064   seq_packet_protocol(const Protocol& source_protocol)
0065     : family_(source_protocol.family()),
0066       protocol_(source_protocol.protocol())
0067   {
0068     if (source_protocol.type() != type())
0069     {
0070       std::bad_cast ex;
0071       boost::asio::detail::throw_exception(ex);
0072     }
0073   }
0074 
0075   /// Obtain an identifier for the type of the protocol.
0076   int type() const noexcept
0077   {
0078     return BOOST_ASIO_OS_DEF(SOCK_SEQPACKET);
0079   }
0080 
0081   /// Obtain an identifier for the protocol.
0082   int protocol() const noexcept
0083   {
0084     return protocol_;
0085   }
0086 
0087   /// Obtain an identifier for the protocol family.
0088   int family() const noexcept
0089   {
0090     return family_;
0091   }
0092 
0093   /// Compare two protocols for equality.
0094   friend bool operator==(const seq_packet_protocol& p1,
0095       const seq_packet_protocol& p2)
0096   {
0097     return p1.family_ == p2.family_ && p1.protocol_ == p2.protocol_;
0098   }
0099 
0100   /// Compare two protocols for inequality.
0101   friend bool operator!=(const seq_packet_protocol& p1,
0102       const seq_packet_protocol& p2)
0103   {
0104     return !(p1 == p2);
0105   }
0106 
0107   /// The type of an endpoint.
0108   typedef basic_endpoint<seq_packet_protocol> endpoint;
0109 
0110   /// The generic socket type.
0111   typedef basic_seq_packet_socket<seq_packet_protocol> socket;
0112 
0113 private:
0114   int family_;
0115   int protocol_;
0116 };
0117 
0118 } // namespace generic
0119 } // namespace asio
0120 } // namespace boost
0121 
0122 #include <boost/asio/detail/pop_options.hpp>
0123 
0124 #endif // BOOST_ASIO_GENERIC_SEQ_PACKET_PROTOCOL_HPP