From 899d252fb92c8b592b3f1d26f4e1eb2db72d0731 Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Sun, 13 May 2007 08:18:09 +0000 Subject: [PATCH] Allow everything to compile on platforms where IPV6_V6ONLY is not defined (such as Linux distros with a 2.4 kernel), but make any use of ip::v6_only fail at runtime. [SVN r37681] --- include/boost/asio/detail/socket_ops.hpp | 12 ++++++++++++ include/boost/asio/detail/socket_types.hpp | 1 + include/boost/asio/ip/v6_only.hpp | 6 +++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/boost/asio/detail/socket_ops.hpp b/include/boost/asio/detail/socket_ops.hpp index 8e6fd96b..39e065b1 100644 --- a/include/boost/asio/detail/socket_ops.hpp +++ b/include/boost/asio/detail/socket_ops.hpp @@ -319,6 +319,12 @@ inline socket_type socket(int af, int type, int protocol, inline int setsockopt(socket_type s, int level, int optname, const void* optval, size_t optlen, boost::system::error_code& ec) { + if (level == custom_socket_option_level && optname == always_fail_option) + { + ec = boost::asio::error::invalid_argument; + return -1; + } + clear_error(ec); #if defined(BOOST_WINDOWS) || defined(__CYGWIN__) return error_wrapper(::setsockopt(s, level, optname, @@ -332,6 +338,12 @@ inline int setsockopt(socket_type s, int level, int optname, inline int getsockopt(socket_type s, int level, int optname, void* optval, size_t* optlen, boost::system::error_code& ec) { + if (level == custom_socket_option_level && optname == always_fail_option) + { + ec = boost::asio::error::invalid_argument; + return -1; + } + clear_error(ec); #if defined(BOOST_WINDOWS) || defined(__CYGWIN__) int tmp_optlen = static_cast(*optlen); diff --git a/include/boost/asio/detail/socket_types.hpp b/include/boost/asio/detail/socket_types.hpp index bf6c67f1..3a42e647 100644 --- a/include/boost/asio/detail/socket_types.hpp +++ b/include/boost/asio/detail/socket_types.hpp @@ -170,6 +170,7 @@ const int message_do_not_route = MSG_DONTROUTE; #endif const int custom_socket_option_level = 0xA5100000; const int enable_connection_aborted_option = 1; +const int always_fail_option = 2; } // namespace detail } // namespace asio diff --git a/include/boost/asio/ip/v6_only.hpp b/include/boost/asio/ip/v6_only.hpp index efe36749..78285fd2 100644 --- a/include/boost/asio/ip/v6_only.hpp +++ b/include/boost/asio/ip/v6_only.hpp @@ -52,9 +52,13 @@ namespace ip { */ #if defined(GENERATING_DOCUMENTATION) typedef implementation_defined v6_only; -#else +#elif defined(IPV6_V6ONLY) typedef boost::asio::detail::socket_option::boolean< IPPROTO_IPV6, IPV6_V6ONLY> v6_only; +#else +typedef boost::asio::detail::socket_option::boolean< + boost::asio::detail::custom_socket_option_level, + boost::asio::detail::always_fail_option> v6_only; #endif } // namespace ip