123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #ifndef ASIO_GENERIC_RAW_PROTOCOL_HPP
- #define ASIO_GENERIC_RAW_PROTOCOL_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include "asio/detail/config.hpp"
- #include <typeinfo>
- #include "asio/basic_raw_socket.hpp"
- #include "asio/detail/socket_types.hpp"
- #include "asio/detail/throw_exception.hpp"
- #include "asio/generic/basic_endpoint.hpp"
- #include "asio/detail/push_options.hpp"
- namespace asio {
- namespace generic {
- class raw_protocol
- {
- public:
-
- raw_protocol(int address_family, int socket_protocol)
- : family_(address_family),
- protocol_(socket_protocol)
- {
- }
-
-
- template <typename Protocol>
- raw_protocol(const Protocol& source_protocol)
- : family_(source_protocol.family()),
- protocol_(source_protocol.protocol())
- {
- if (source_protocol.type() != type())
- {
- std::bad_cast ex;
- asio::detail::throw_exception(ex);
- }
- }
-
- int type() const noexcept
- {
- return ASIO_OS_DEF(SOCK_RAW);
- }
-
- int protocol() const noexcept
- {
- return protocol_;
- }
-
- int family() const noexcept
- {
- return family_;
- }
-
- friend bool operator==(const raw_protocol& p1, const raw_protocol& p2)
- {
- return p1.family_ == p2.family_ && p1.protocol_ == p2.protocol_;
- }
-
- friend bool operator!=(const raw_protocol& p1, const raw_protocol& p2)
- {
- return !(p1 == p2);
- }
-
- typedef basic_endpoint<raw_protocol> endpoint;
-
- typedef basic_raw_socket<raw_protocol> socket;
- private:
- int family_;
- int protocol_;
- };
- }
- }
- #include "asio/detail/pop_options.hpp"
- #endif
|