]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Use <sys/socket.h> features conditionally [PR 100285]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 30 Apr 2021 13:25:25 +0000 (14:25 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 24 Aug 2021 14:13:18 +0000 (15:13 +0100)
This makes the uses of getsockopt and setsockopt in
<experimental/socket> conditional on the availability of <sys/socket.h>.

It also fixes a test to check for <sys/socket.h> instead of <socket.h>.

libstdc++-v3/ChangeLog:

PR libstdc++/100285
* include/experimental/socket (__basic_socket_impl::set_option)
(__basic_socket_impl::get_option) [!_GLIBCXX_HAVE_SYS_SOCKET_H]:
Just set error code.
* testsuite/experimental/net/socket/socket_base.cc: CHeck
for <sys/socket.h> not <socket.h>.

(cherry picked from commit 0d501c338548152f9d2728d383eec3e9cef16784)

libstdc++-v3/include/experimental/socket
libstdc++-v3/testsuite/experimental/net/socket/socket_base.cc

index bf6a8c87e67db283e47594b45ee0f7c9f2b6ea52..9db4a245ccfc9a3ff64ceab194ce081fba871eb2 100644 (file)
@@ -622,6 +622,7 @@ inline namespace v1
        void
        set_option(const _SettableSocketOption& __option, error_code& __ec)
        {
+# ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
          int __result = ::setsockopt(_M_sockfd, __option.level(_M_protocol),
                                      __option.name(_M_protocol),
                                      __option.data(_M_protocol),
@@ -630,12 +631,16 @@ inline namespace v1
            __ec.assign(errno, generic_category());
          else
            __ec.clear();
+#else
+         __ec = std::make_error_code(std::errc::not_supported);
+#endif
        }
 
       template<typename _GettableSocketOption>
        void
        get_option(_GettableSocketOption& __option, error_code& __ec) const
        {
+# ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
          int __result = ::getsockopt(_M_sockfd, __option.level(_M_protocol),
                                      __option.name(_M_protocol),
                                      __option.data(_M_protocol),
@@ -644,6 +649,9 @@ inline namespace v1
            __ec.assign(errno, generic_category());
          else
            __ec.clear();
+#else
+         __ec = std::make_error_code(std::errc::not_supported);
+#endif
        }
 
       template<typename _IoControlCommand>
index 1c02c5a09dac69ad0a2fe662a36c2d381895f17f..f957b6c92f6509dcca6886b152c8d4ad48b48e78 100644 (file)
@@ -129,7 +129,7 @@ void check_integer_sockopt()
 
 void test_option_types()
 {
-#if __has_include(<socket.h>)
+#if __has_include(<sys/socket.h>)
   check_boolean_sockopt<S::broadcast>();
 
   check_boolean_sockopt<S::debug>();
@@ -174,7 +174,7 @@ void test_option_types()
 
 void test_constants()
 {
-#if __has_include(<socket.h>)
+#if __has_include(<sys/socket.h>)
   static_assert( is_enum<S::shutdown_type>::value, "" );
   static_assert( S::shutdown_receive != S::shutdown_send, "" );
   static_assert( S::shutdown_receive != S::shutdown_both, "" );