Use autoconf to check for features needed by Networking TS
authorJonathan Wakely <jwakely@redhat.com>
Tue, 16 Oct 2018 16:12:32 +0000 (17:12 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 16 Oct 2018 16:12:32 +0000 (17:12 +0100)
* config.h.in: Regenerate.
* configure: Regenerate.
* configure.ac: Check for headers used by Networking TS.
* include/experimental/executor: Include <condition_variable>
instead of <mutex>.
* include/experimental/internet: Use autoconf macros for available
headers.  Include <sys/socket.h> for.  Remove <cstring> and use
__builtin_memcpy and __builtin_strchr.
(resolver_errc) [!_GLIBCXX_HAVE_NETDB_H]: Do not define.
(address_v4::to_string, address_v6::to_string)
[!_GLIBCXX_HAVE_ARPA_INET_H]: Likewise.
(basic_resolver_results) [!_GLIBCXX_HAVE_NETDB_H]: Make private
constructors report errors.
[!_GLIBCXX_HAVE_NETINET_TCP_H] (tcp::no_delay): Do not define.
* include/experimental/io_context: Likewise.
* include/experimental/socket: Likewise.
[!_GLIBCXX_HAVE_SYS_SOCKET_H, !_GLIBCXX_HAVE_POLL_H] (socket_base): Do
not define nested types when relevant header not available.
(__socket_impl::native_non_blocking) [!_GLIBCXX_HAVE_FCNTL_H]: Report
an error.
(__basic_socket_impl::open, __basic_socket_impl::local_endpoint)
(__basic_socket_impl::bind) [!_GLIBCXX_HAVE_SYS_SOCKET_H]: Likewise.
(__basic_socket_impl::io_control) [!_GLIBCXX_HAVE_SYS_IOCTL_H]:
Likewise.
(basic_socket::at_mark, basic_socket::shutdown)
(basic_socket::remote_endpoint, basic_socket::connect)
(basic_socket::async_connect) [!_GLIBCXX_HAVE_SYS_SOCKET_H]: Likewise.
(basic_socket::available) [_GLIBCXX_HAVE_SYS_IOCTL_H]: Check macro
for <sys/ioctl.h> availability.
(basic_socket::wait) [!_GLIBCXX_HAVE_POLL_H]: Likewise.
(basic_datagram_socket::receive, basic_datagram_socket::async_receive)
(basic_datagram_socket::receive_from)
(basic_datagram_socket::async_receive_from)
(basic_datagram_socket::send, basic_datagram_socket::async_send)
(basic_datagram_socket::send_to, basic_datagram_socket::async_send_to)
[!_GLIBCXX_HAVE_SYS_SOCKET_H]: Likewise.
(basic_stream_socket::receive, basic_stream_socket::async_receive)
(basic_stream_socket::send, basic_stream_socket::async_send)
[!_GLIBCXX_HAVE_SYS_SOCKET_H]: Likewise.
(basic_socket_acceptor::listen, basic_socket_acceptor::accept)
(basic_socket_acceptor::async_accept) [!_GLIBCXX_HAVE_SYS_SOCKET_H]:
Likewise.
(basic_socket_acceptor::wait) [!_GLIBCXX_HAVE_POLL_H]: Likewise.

From-SVN: r265203

libstdc++-v3/ChangeLog
libstdc++-v3/config.h.in
libstdc++-v3/configure
libstdc++-v3/configure.ac
libstdc++-v3/include/experimental/executor
libstdc++-v3/include/experimental/internet
libstdc++-v3/include/experimental/io_context
libstdc++-v3/include/experimental/socket

index a836ec58f45d0d7d06df1023a0dd515ff98740a3..681e88cb3a284e1bf84528a6fd7e802d54ca1335 100644 (file)
@@ -1,5 +1,49 @@
 2018-10-16  Jonathan Wakely  <jwakely@redhat.com>
 
+       * config.h.in: Regenerate.
+       * configure: Regenerate.
+       * configure.ac: Check for headers used by Networking TS.
+       * include/experimental/executor: Include <condition_variable>
+       instead of <mutex>.
+       * include/experimental/internet: Use autoconf macros for available
+       headers.  Include <sys/socket.h> for.  Remove <cstring> and use
+       __builtin_memcpy and __builtin_strchr.
+       (resolver_errc) [!_GLIBCXX_HAVE_NETDB_H]: Do not define.
+       (address_v4::to_string, address_v6::to_string)
+       [!_GLIBCXX_HAVE_ARPA_INET_H]: Likewise.
+       (basic_resolver_results) [!_GLIBCXX_HAVE_NETDB_H]: Make private
+       constructors report errors.
+       [!_GLIBCXX_HAVE_NETINET_TCP_H] (tcp::no_delay): Do not define.
+       * include/experimental/io_context: Likewise.
+       * include/experimental/socket: Likewise.
+       [!_GLIBCXX_HAVE_SYS_SOCKET_H, !_GLIBCXX_HAVE_POLL_H] (socket_base): Do
+       not define nested types when relevant header not available.
+       (__socket_impl::native_non_blocking) [!_GLIBCXX_HAVE_FCNTL_H]: Report
+       an error.
+       (__basic_socket_impl::open, __basic_socket_impl::local_endpoint)
+       (__basic_socket_impl::bind) [!_GLIBCXX_HAVE_SYS_SOCKET_H]: Likewise.
+       (__basic_socket_impl::io_control) [!_GLIBCXX_HAVE_SYS_IOCTL_H]:
+       Likewise.
+       (basic_socket::at_mark, basic_socket::shutdown)
+       (basic_socket::remote_endpoint, basic_socket::connect)
+       (basic_socket::async_connect) [!_GLIBCXX_HAVE_SYS_SOCKET_H]: Likewise.
+       (basic_socket::available) [_GLIBCXX_HAVE_SYS_IOCTL_H]: Check macro
+       for <sys/ioctl.h> availability.
+       (basic_socket::wait) [!_GLIBCXX_HAVE_POLL_H]: Likewise.
+       (basic_datagram_socket::receive, basic_datagram_socket::async_receive)
+       (basic_datagram_socket::receive_from)
+       (basic_datagram_socket::async_receive_from)
+       (basic_datagram_socket::send, basic_datagram_socket::async_send)
+       (basic_datagram_socket::send_to, basic_datagram_socket::async_send_to)
+       [!_GLIBCXX_HAVE_SYS_SOCKET_H]: Likewise.
+       (basic_stream_socket::receive, basic_stream_socket::async_receive)
+       (basic_stream_socket::send, basic_stream_socket::async_send)
+       [!_GLIBCXX_HAVE_SYS_SOCKET_H]: Likewise.
+       (basic_socket_acceptor::listen, basic_socket_acceptor::accept)
+       (basic_socket_acceptor::async_accept) [!_GLIBCXX_HAVE_SYS_SOCKET_H]:
+       Likewise.
+       (basic_socket_acceptor::wait) [!_GLIBCXX_HAVE_POLL_H]: Likewise.
+
        * testsuite/experimental/net/headers.cc: Remove dg-options.
        * testsuite/experimental/net/buffer/arithmetic.cc: Replace dg-options
        with dg-do using effective target.
index 65e7b46dc4e62c6144c8ca91a9cc960302ce2339..fa69b7a08955b55651106ab97ae3add9f63a58c9 100644 (file)
@@ -9,6 +9,9 @@
 /* Define to 1 if you have the `aligned_alloc' function. */
 #undef HAVE_ALIGNED_ALLOC
 
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+#undef HAVE_ARPA_INET_H
+
 /* Define to 1 if you have the `asinf' function. */
 #undef HAVE_ASINF
 
 /* Define to 1 if you have the <nan.h> header file. */
 #undef HAVE_NAN_H
 
+/* Define to 1 if you have the <netdb.h> header file. */
+#undef HAVE_NETDB_H
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#undef HAVE_NETINET_IN_H
+
+/* Define to 1 if you have the <netinet/tcp.h> header file. */
+#undef HAVE_NETINET_TCP_H
+
 /* Define if <math.h> defines obsolete isinf function. */
 #undef HAVE_OBSOLETE_ISINF
 
 /* Define if poll is available in <poll.h>. */
 #undef HAVE_POLL
 
+/* Define to 1 if you have the <poll.h> header file. */
+#undef HAVE_POLL_H
+
 /* Define to 1 if you have the `posix_memalign' function. */
 #undef HAVE_POSIX_MEMALIGN
 
 /* Define to 1 if you have the <sys/sem.h> header file. */
 #undef HAVE_SYS_SEM_H
 
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#undef HAVE_SYS_SOCKET_H
+
 /* Define to 1 if you have the <sys/statvfs.h> header file. */
 #undef HAVE_SYS_STATVFS_H
 
index 93a727e7cff4e02f21cb227f43a15a81304bac2d..12a6d4cf0efbaf6f1e0e49330630f47fc5336d35 100755 (executable)
@@ -80699,6 +80699,22 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
   fi
 
 
+# For Networking TS.
+for ac_header in fcntl.h sys/ioctl.h sys/socket.h sys/uio.h poll.h netdb.h arpa/inet.h netinet/in.h netinet/tcp.h
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
+eval as_val=\$$as_ac_Header
+   if test "x$as_val" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
 # For Transactional Memory TS
 
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking how size_t is mangled" >&5
index e3612b036df6822203128b4d244ba4f0a0a1db1d..dbb7dbc137cfd31b893aa8c4e33c19372771d8fc 100644 (file)
@@ -423,6 +423,9 @@ AC_CHECK_HEADERS([fcntl.h dirent.h sys/statvfs.h utime.h])
 GLIBCXX_ENABLE_FILESYSTEM_TS
 GLIBCXX_CHECK_FILESYSTEM_DEPS
 
+# For Networking TS.
+AC_CHECK_HEADERS([fcntl.h sys/ioctl.h sys/socket.h sys/uio.h poll.h netdb.h arpa/inet.h netinet/in.h netinet/tcp.h])
+
 # For Transactional Memory TS
 GLIBCXX_CHECK_SIZE_T_MANGLING
 
index cd4adb58b0d97f0e32654c1847aa24dfc4eec122..db8df4b871bbbc6bea5b258353ed74930d1a307b 100644 (file)
 #if __cplusplus >= 201402L
 
 #include <algorithm>
+#include <condition_variable>
 #include <functional>
 #include <future>
 #include <list>
-#include <mutex>
 #include <queue>
 #include <thread>
 #include <tuple>
index 07fe6140f30072a58e5947117dadd7002bdfb46d..402a0474a9534dc01e28b1fba4a74aeeb0523fa0 100644 (file)
 #if __cplusplus >= 201402L
 
 #include <experimental/netfwd>
+#include <experimental/io_context>
+#include <experimental/bits/net.h>
 #include <array>
 #include <forward_list>
 #include <sstream>
-#include <typeinfo>
-#include <cstring>
 #include <cstdint>
-#include <experimental/io_context>
-#include <experimental/bits/net.h>
 #include <experimental/string_view>
-#include <unistd.h>
-#include <arpa/inet.h>
-#include <netinet/tcp.h>
-#include <netdb.h>
+#ifdef _GLIBCXX_HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
+# include <sys/socket.h>       // AF_INET, AF_INET6, SOCK_DGRAM, SOCK_STREAM
+#endif
+#ifdef _GLIBCXX_HAVE_ARPA_INET_H
+# include <arpa/inet.h>                // inet_ntop
+#endif
+#ifdef _GLIBCXX_HAVE_NETINET_TCP_H
+# include <netinet/tcp.h>      // TCP_NODELAY
+#endif
+#ifdef _GLIBCXX_HAVE_NETDB_H
+# include <netdb.h>            // getaddrinfo etc.
+#endif
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -65,6 +74,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    * @{
    */
 
+#ifdef _GLIBCXX_HAVE_NETDB_H
   /** Error codes for resolver errors.
    * @{
    */
@@ -95,6 +105,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { return error_condition(static_cast<int>(__e), resolver_category()); }
 
   /// @}
+#endif
 
   typedef uint_least16_t port_type;    ///< Type used for port numbers.
   typedef uint_least32_t scope_id_type;        ///< Type used for IPv6 scope IDs.
@@ -182,6 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
     constexpr uint_type to_uint() const noexcept { return _S_ntoh(_M_addr); }
 
+#ifdef _GLIBCXX_HAVE_ARPA_INET_H
     template<typename _Allocator = allocator<char>>
       __string_with<_Allocator>
       to_string(const _Allocator& __a = _Allocator()) const
@@ -194,6 +206,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          __str.resize(0);
        return __str;
       }
+#endif
 
     // static members:
     static constexpr address_v4 any() noexcept { return address_v4{}; }
@@ -321,6 +334,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
     constexpr bytes_type to_bytes() const noexcept { return _M_bytes; }
 
+#ifdef _GLIBCXX_HAVE_ARPA_INET_H
     template<typename _Allocator = allocator<char>>
       __string_with<_Allocator>
       to_string(const _Allocator& __a = _Allocator()) const
@@ -333,13 +347,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          __str.resize(0);
        return __str;
       }
+#endif
 
     // static members:
     static constexpr address_v6
     any() noexcept
     {
       address_v6 __addr;
-      std::memcpy(&__addr._M_bytes, in6addr_any.s6_addr, 16);
+      __builtin_memcpy(&__addr._M_bytes, in6addr_any.s6_addr, 16);
       return __addr;
     }
 
@@ -347,7 +362,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     loopback() noexcept
     {
       address_v6 __addr;
-      std::memcpy(&__addr._M_bytes, in6addr_loopback.s6_addr, 16);
+      __builtin_memcpy(&__addr._M_bytes, in6addr_loopback.s6_addr, 16);
       return __addr;
     }
 
@@ -717,7 +732,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   inline address_v6
   make_address_v6(const char* __str, error_code& __ec) noexcept
   {
-    auto __p = std::strchr(__str, '%');
+    auto __p = __builtin_strchr(__str, '%');
     if (__p == nullptr)
       return __make_address_v6(__str, nullptr, __ec);
     char __buf[64];
@@ -1400,8 +1415,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
            _M_data._M_v6 = {};
            _M_data._M_v6.sin6_family = protocol_type::v6().family();
            _M_data._M_v6.sin6_port = address_v4::_S_hton(__port_num);
-           std::memcpy(_M_data._M_v6.sin6_addr.s6_addr,
-                       __addr._M_v6._M_bytes.data(), 16);
+           __builtin_memcpy(_M_data._M_v6.sin6_addr.s6_addr,
+                            __addr._M_v6._M_bytes.data(), 16);
            _M_data._M_v6.sin6_scope_id = __addr._M_v6._M_scope_id;
          }
       }
@@ -1419,14 +1434,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        ip::address __addr;
        if (protocol().family() == AF_INET6)
          {
-           std::memcpy(&__addr._M_v6._M_bytes,
-                       _M_data._M_v6.sin6_addr.s6_addr, 16);
+           __builtin_memcpy(&__addr._M_v6._M_bytes,
+                            _M_data._M_v6.sin6_addr.s6_addr, 16);
            __addr._M_is_v4 = false;
          }
        else
          {
-           std::memcpy(&__addr._M_v4._M_addr,
-                       &_M_data._M_v4.sin_addr.s_addr, 4);
+           __builtin_memcpy(&__addr._M_v4._M_addr,
+                            &_M_data._M_v4.sin_addr.s_addr, 4);
          }
        return __addr;
       }
@@ -1438,8 +1453,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          {
            _M_data._M_v6 = {};
            _M_data._M_v6.sin6_family = protocol_type::v6().family();
-           std::memcpy(_M_data._M_v6.sin6_addr.s6_addr,
-                       __addr._M_v6._M_bytes.data(), 16);
+           __builtin_memcpy(_M_data._M_v6.sin6_addr.s6_addr,
+                            __addr._M_v6._M_bytes.data(), 16);
            _M_data._M_v6.sin6_scope_id = __addr._M_v6._M_scope_id;
          }
        else
@@ -1660,7 +1675,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   operator^=(resolver_base::flags& __f1, resolver_base::flags __f2)
   { return __f1 = (__f1 ^ __f2); }
 
-  // TODO define resolver_base::flags static constants
+  // TODO define resolver_base::flags static constants for C++14 mode
 
   // @}
 
@@ -1898,6 +1913,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                           resolver_base::flags __f, error_code& __ec,
                           protocol_type* __protocol)
     {
+#ifdef _GLIBCXX_HAVE_NETDB_H
       string __host;
       const char* __h = __host_name.data()
        ? (__host = __host_name.to_string()).c_str()
@@ -1943,12 +1959,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          if (__ai->ai_family == AF_INET || __ai->ai_family == AF_INET6)
            {
              if (__ai->ai_addrlen <= __ep.capacity())
-               std::memcpy(__ep.data(), __ai->ai_addr, __ai->ai_addrlen);
+               __builtin_memcpy(__ep.data(), __ai->ai_addr, __ai->ai_addrlen);
              __ep.resize(__ai->ai_addrlen);
              __tail = _M_results.emplace_after(__tail, __ep, __host, __svc);
              _M_size++;
            }
        }
+#else
+      __ec = std::make_error_code(errc::operation_not_supported);
+#endif
     }
 
   /// Private constructor to synchronously resolve an endpoint.
@@ -1956,6 +1975,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     basic_resolver_results<_InternetProtocol>::
     basic_resolver_results(const endpoint_type& __ep, error_code& __ec)
     {
+#ifdef _GLIBCXX_HAVE_NETDB_H
       char __host_name[256];
       char __service_name[128];
       int __flags = 0;
@@ -1982,6 +2002,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          _M_results.emplace_front(__ep, __host_name, __service_name);
          _M_size = 1;
        }
+#else
+      __ec = std::make_error_code(errc::operation_not_supported);
+#endif
     }
 
   /** The name of the local host.
@@ -2030,6 +2053,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     typedef basic_socket_acceptor<tcp> acceptor; ///< A TCP acceptor.
     typedef basic_socket_iostream<tcp> iostream; /// A TCP iostream.
 
+#ifdef _GLIBCXX_HAVE_NETINET_TCP_H
     /// Disable coalescing of small segments (i.e. the Nagle algorithm).
     struct no_delay : __sockopt_crtp<no_delay, bool>
     {
@@ -2038,6 +2062,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       static const int _S_level = IPPROTO_TCP;
       static const int _S_name = TCP_NODELAY;
     };
+#endif
 
     // static members:
 
index 7b42442a0348122d92fad5f1baea4f50c7f273f7..b8d231f7e683da263246b44b9d6a9aa9359a93ba 100644 (file)
 #include <thread>
 #include <experimental/netfwd>
 #include <experimental/executor>
-#include <unistd.h>
-#include <poll.h>
-#include <fcntl.h>
+#if _GLIBCXX_HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#ifdef _GLIBCXX_HAVE_POLL_H
+# include <poll.h>
+#endif
+#ifdef _GLIBCXX_HAVE_FCNTL_H
+# include <fcntl.h>
+#endif
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -775,6 +781,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        _M_notify();
       }
 
+# ifdef _GLIBCXX_HAVE_POLL_H
       using __fdvec = vector<::pollfd>;
 
       // Find first element p such that !(p.fd < __fd)
@@ -823,6 +830,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       }
 
       __fdvec _M_fds;  // _M_fds.back() is the read end of the self-pipe
+#endif
       int _M_notify_wr;        // write end of the self-pipe
     };
 
index e92a4374db906d4bba5d3b41b3a35508845c2946..e903eb824b28b8632e1ea0fdbe16d0536cddeb83 100644 (file)
 #include <bits/unique_ptr.h>
 #if _GLIBCXX_HAVE_UNISTD_H
 # include <unistd.h>
-# include <sys/socket.h>
-# include <sys/ioctl.h>
-# include <sys/fcntl.h>
-# include <sys/uio.h>
-# include <poll.h>
+# ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
+#  include <sys/socket.h>      // socket etc
+# endif
+# ifdef _GLIBCXX_HAVE_SYS_IOCTL_H
+#  include <sys/ioctl.h>       // ioctl
+# endif
+# ifdef _GLIBCXX_HAVE_SYS_UIO_H
+#  include <sys/uio.h>         // iovec
+# endif
+# ifdef _GLIBCXX_HAVE_POLL_H
+#  include <poll.h>            // poll, pollfd, POLLIN, POLLOUT, POLLERR
+# endif
+# ifdef _GLIBCXX_HAVE_FCNTL_H
+#  include <fcntl.h>           // fcntl, F_GETFL, F_SETFL
+# endif
 #endif
 
 namespace std _GLIBCXX_VISIBILITY(default)
@@ -139,6 +149,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   class socket_base
   {
   public:
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
     struct broadcast : __sockopt_crtp<broadcast, bool>
     {
       using __sockopt_crtp::__sockopt_crtp;
@@ -261,6 +272,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     static constexpr shutdown_type shutdown_send       = __shutdown_send;
     static constexpr shutdown_type shutdown_both       = __shutdown_both;
 
+#ifdef _GLIBCXX_HAVE_POLL_H
     enum wait_type : int
     {
       __wait_read              = POLLIN,
@@ -270,6 +282,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     static constexpr wait_type wait_read               = __wait_read;
     static constexpr wait_type wait_write              = __wait_write;
     static constexpr wait_type wait_error              = __wait_error;
+#endif
 
     enum message_flags : int
     {
@@ -282,11 +295,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     static constexpr message_flags message_do_not_route        = __message_dontroute;
 
     static const int max_listen_connections = SOMAXCONN;
+#endif
 
   protected:
     socket_base() = default;
     ~socket_base() = default;
 
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
     struct __msg_hdr : ::msghdr
     {
 #ifdef IOV_MAX
@@ -342,6 +357,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          this->msg_namelen = __ep.size();
        }
     };
+#endif
   };
 
   constexpr socket_base::message_flags
@@ -440,6 +456,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     void
     native_non_blocking(bool __mode, error_code& __ec)
     {
+#ifdef _GLIBCXX_HAVE_FCNTL_H
       int __flags = ::fcntl(_M_sockfd, F_GETFL, 0);
       if (__flags >= 0)
        {
@@ -456,11 +473,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          __ec.clear();
          _M_bits.native_non_blocking = __mode;
        }
+#else
+      __ec = std::make_error_code(std::errc::not_supported);
+#endif
     }
 
     bool
     native_non_blocking() const
     {
+#ifdef _GLIBCXX_HAVE_FCNTL_H
       if (_M_bits.native_non_blocking == -1)
        {
          const int __flags = ::fcntl(_M_sockfd, F_GETFL, 0);
@@ -469,6 +490,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          _M_bits.native_non_blocking = __flags & O_NONBLOCK;
        }
       return _M_bits.native_non_blocking;
+#else
+      return false;
+#endif
     }
 
     io_context*        _M_ctx;
@@ -517,6 +541,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       void
       open(const protocol_type& __protocol, error_code& __ec)
       {
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
        if (is_open())
          __ec = socket_errc::already_open;
        else
@@ -532,6 +557,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
            else
              __ec.assign(errno, std::generic_category());
          }
+#else
+       __ec = std::make_error_code(errc::operation_not_supported);
+#endif
       }
 
       void
@@ -588,18 +616,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        void
        io_control(_IoControlCommand& __command, error_code& __ec)
        {
-         int __result = ::ioctl(_M_sockfd, __command.name(_M_protocol),
-                                __command.data(_M_protocol));
+#ifdef _GLIBCXX_HAVE_SYS_IOCTL_H
+         int __result = ::ioctl(_M_sockfd, __command.name(),
+                                __command.data());
          if (__result == -1)
            __ec.assign(errno, generic_category());
          else
            __ec.clear();
+#else
+         __ec = std::make_error_code(std::errc::not_supported);
+#endif
        }
 
       endpoint_type
       local_endpoint(error_code& __ec) const
       {
        endpoint_type __endpoint;
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
        socklen_t __endpoint_len = __endpoint.capacity();
        if (::getsockname(_M_sockfd, (sockaddr*)__endpoint.data(),
                           &__endpoint_len) == -1)
@@ -609,17 +642,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          }
        __ec.clear();
        __endpoint.resize(__endpoint_len);
+#else
+       __ec = std::make_error_code(errc::operation_not_supported);
+#endif
        return __endpoint;
       }
 
       void
       bind(const endpoint_type& __endpoint, error_code& __ec)
       {
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
        if (::bind(_M_sockfd, (sockaddr*)__endpoint.data(), __endpoint.size())
            == -1)
          __ec.assign(errno, generic_category());
        else
          __ec.clear();
+#else
+       __ec = std::make_error_code(errc::operation_not_supported);
+#endif
       }
 
       _Protocol        _M_protocol{ endpoint_type{}.protocol() };
@@ -754,6 +794,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       bool
       at_mark(error_code& __ec) const
       {
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
        const int __result = ::sockatmark(native_handle());
        if (__result == -1)
          {
@@ -762,6 +803,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          }
        __ec.clear();
        return (bool)__result;
+#else
+       __ec = std::make_error_code(errc::operation_not_supported);
+       return false;
+#endif
       }
 
       size_t
@@ -776,7 +821,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
            __ec = std::make_error_code(errc::bad_file_descriptor);
            return 0;
          }
-#ifdef FIONREAD
+#if defined _GLIBCXX_HAVE_SYS_IOCTL_H && defined FIONREAD
        int __avail = 0;
        if (::ioctl(this->_M_sockfd, FIONREAD, &__avail) == -1)
          {
@@ -804,10 +849,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       void
       shutdown(shutdown_type __what, error_code& __ec)
       {
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
        if (::shutdown(native_handle(), static_cast<int>(__what)) == -1)
          __ec.assign(errno, generic_category());
        else
          __ec.clear();
+#else
+       __ec = std::make_error_code(errc::operation_not_supported);
+#endif
       }
 
       endpoint_type
@@ -832,6 +881,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       remote_endpoint(error_code& __ec) const
       {
        endpoint_type __endpoint;
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
        socklen_t __endpoint_len = __endpoint.capacity();
        if (::getpeername(this->_M_sockfd, (sockaddr*)__endpoint.data(),
                           &__endpoint_len)
@@ -842,6 +892,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          }
        __ec.clear();
        __endpoint.resize(__endpoint_len);
+#else
+       __ec = std::make_error_code(errc::operation_not_supported);
+#endif
        return __endpoint;
       }
 
@@ -860,11 +913,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
            if (__ec)
              return;
          }
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
        if (::connect(native_handle(), (const sockaddr*)__endpoint.data(),
                      __endpoint.size()) == -1)
          __ec.assign(errno, generic_category());
        else
          __ec.clear();
+#else
+       __ec = std::make_error_code(errc::operation_not_supported);
+#endif
       }
 
       template<typename _CompletionToken>
@@ -898,9 +955,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                __ep = std::move(__endpoint),
                __fd = native_handle()]
                (error_code __ec) mutable {
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
                   if (!__ec && ::connect(__fd, (const sockaddr*)__ep.data(),
                                         __ep.size()) == -1)
                     __ec.assign(errno, generic_category());
+#else
+                 __ec = std::make_error_code(errc::operation_not_supported);
+#endif
                  __h(__ec);
              });
          return __init.result.get();
@@ -913,6 +974,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       void
       wait(wait_type __w, error_code& __ec)
       {
+#ifdef _GLIBCXX_HAVE_POLL_H
        ::pollfd __fd;
        __fd.fd = native_handle();
        __fd.events = static_cast<int>(__w);
@@ -921,6 +983,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          __ec.assign(errno, generic_category());
        else
          __ec.clear();
+#else
+       __ec = std::make_error_code(errc::operation_not_supported);
+#endif
       }
 
       template<typename _CompletionToken>
@@ -1060,6 +1125,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        receive(const _MutableBufferSequence& __buffers,
                socket_base::message_flags __flags, error_code& __ec)
        {
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
          socket_base::__msg_hdr __msg(__buffers);
          ssize_t __result = ::recvmsg(this->native_handle(), &__msg,
                                       static_cast<int>(__flags));
@@ -1070,6 +1136,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
             }
           __ec.clear();
           return __result;
+#else
+         __ec = std::make_error_code(errc::operation_not_supported);
+         return 0;
+#endif
        }
 
       template<typename _MutableBufferSequence, typename _CompletionToken>
@@ -1101,6 +1171,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                       __h(__ec);
                       return;
                     }
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
                   socket_base::__msg_hdr __msg(__buffers);
                   ssize_t __result = ::recvmsg(__fd, &__msg, __flags);
                   if (__result == -1)
@@ -1111,6 +1182,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                   else
                     __ec.clear();
                  __h(__ec, __result);
+#else
+                 __h(std::make_error_code(errc::operation_not_supported), 0);
+#endif
              });
          return __init.result.get();
        }
@@ -1153,6 +1227,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                     socket_base::message_flags __flags,
                     error_code& __ec)
        {
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
          socket_base::__msg_hdr __msg(__buffers, __sender);
          ssize_t __result = ::recvmsg(this->native_handle(), &__msg,
                                       static_cast<int>(__flags));
@@ -1164,6 +1239,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
           __ec.clear();
           __sender.resize(__msg.msg_namelen);
           return __result;
+#else
+         __ec = std::make_error_code(errc::operation_not_supported);
+         return 0;
+#endif
        }
 
       template<typename _MutableBufferSequence, typename _CompletionToken>
@@ -1199,6 +1278,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                       __h(__ec);
                       return;
                     }
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
                   socket_base::__msg_hdr __msg(__buffers, __sender);
                   ssize_t __result = ::recvmsg(__fd, &__msg, __flags);
                   if (__result == -1)
@@ -1212,6 +1292,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                       __sender.resize(__msg.msg_namelen);
                     }
                  __h(__ec, __result);
+#else
+                 __h(std::make_error_code(errc::operation_not_supported), 0);
+#endif
              });
          return __init.result.get();
        }
@@ -1243,6 +1326,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        send(const _ConstBufferSequence& __buffers,
             socket_base::message_flags __flags, error_code& __ec)
        {
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
          socket_base::__msg_hdr __msg(__buffers);
          ssize_t __result = ::sendmsg(this->native_handle(), &__msg,
                                       static_cast<int>(__flags));
@@ -1253,6 +1337,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
             }
           __ec.clear();
           return __result;
+#else
+         __ec = std::make_error_code(errc::operation_not_supported);
+         return 0;
+#endif
        }
 
       template<typename _ConstBufferSequence, typename _CompletionToken>
@@ -1284,6 +1372,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                       __h(__ec);
                       return;
                     }
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
                   socket_base::__msg_hdr __msg(__buffers);
                   ssize_t __result = ::sendmsg(__fd, &__msg, __flags);
                   if (__result == -1)
@@ -1294,6 +1383,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                   else
                     __ec.clear();
                  __h(__ec, __result);
+#else
+                 __h(std::make_error_code(errc::operation_not_supported), 0);
+#endif
              });
          return __init.result.get();
        }
@@ -1333,6 +1425,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                const endpoint_type& __recipient,
                socket_base::message_flags __flags, error_code& __ec)
        {
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
          socket_base::__msg_hdr __msg(__buffers, __recipient);
          ssize_t __result = ::sendmsg(this->native_handle(), &__msg,
                                       static_cast<int>(__flags));
@@ -1344,6 +1437,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
           __ec.clear();
           __recipient.resize(__msg.msg_namelen);
           return __result;
+#else
+         __ec = std::make_error_code(errc::operation_not_supported);
+         return 0;
+#endif
        }
 
       template<typename _ConstBufferSequence, typename _CompletionToken>
@@ -1379,6 +1476,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                       __h(__ec);
                       return;
                     }
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
                   socket_base::__msg_hdr __msg(__buffers, __recipient);
                   ssize_t __result = ::sendmsg(__fd, &__msg, __flags);
                   if (__result == -1)
@@ -1392,6 +1490,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                       __recipient.resize(__msg.msg_namelen);
                     }
                  __h(__ec, __result);
+#else
+                 __h(std::make_error_code(errc::operation_not_supported), 0);
+#endif
              });
          return __init.result.get();
        }
@@ -1482,7 +1583,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
              __ec.clear();
              return 0;
            }
-
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
          socket_base::__msg_hdr __msg(__buffers);
          ssize_t __result = ::recvmsg(this->native_handle(), &__msg,
                                       static_cast<int>(__flags));
@@ -1492,6 +1593,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
              return __result;
            }
          __ec.assign(errno, generic_category());
+#else
+         __ec = std::make_error_code(errc::operation_not_supported);
+#endif
          return 0;
        }
 
@@ -1536,6 +1640,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                       __h(__ec);
                       return;
                     }
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
                   socket_base::__msg_hdr __msg(__buffers);
                   ssize_t __result = ::recvmsg(__fd, &__msg, __flags);
                   if (__result == -1)
@@ -1546,6 +1651,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                   else
                     __ec.clear();
                  __h(__ec, __result);
+#else
+                 __h(std::make_error_code(errc::operation_not_supported), 0);
+#endif
              });
          return __init.result.get();
        }
@@ -1582,7 +1690,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
              __ec.clear();
              return 0;
            }
-
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
          socket_base::__msg_hdr __msg(__buffers);
          ssize_t __result = ::sendmsg(this->native_handle(), &__msg,
                                       static_cast<int>(__flags));
@@ -1592,6 +1700,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
              return __result;
            }
          __ec.assign(errno, generic_category());
+#else
+         __ec = std::make_error_code(errc::operation_not_supported);
+#endif
          return 0;
        }
 
@@ -1636,6 +1747,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                       __h(__ec);
                       return;
                     }
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
                   socket_base::__msg_hdr __msg(__buffers);
                   ssize_t __result = ::sendmsg(__fd, &__msg, __flags);
                   if (__result == -1)
@@ -1646,6 +1758,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                   else
                     __ec.clear();
                  __h(__ec, __result);
+#else
+                 __h(std::make_error_code(errc::operation_not_supported), 0);
+#endif
              });
          return __init.result.get();
        }
@@ -1889,12 +2004,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                      __throw_on_error{"basic_socket_acceptor::listen"});
       }
 
-      void listen(int __backlog, error_code& __ec)
+      void
+      listen(int __backlog, error_code& __ec)
       {
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
        if (::listen(native_handle(), __backlog) == -1)
          __ec.assign(errno, generic_category());
        else
          __ec.clear();
+#else
+       __ec = std::make_error_code(errc::operation_not_supported);
+#endif
       }
 
       endpoint_type
@@ -1933,6 +2053,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       socket_type
       accept(io_context& __ctx, error_code& __ec)
       {
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
        do
          {
            int __h = ::accept(native_handle(), nullptr, 0);
@@ -1943,6 +2064,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
              }
          } while (errno == ECONNABORTED && enable_connection_aborted());
        __ec.assign(errno, generic_category());
+#else
+       __ec = std::make_error_code(errc::operation_not_supported);
+#endif
        return socket_type{__ctx};
       }
 
@@ -1975,6 +2099,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                       __h(__ec, socket_type(__ctx));
                       return;
                     }
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
                   do
                     {
                       int __newfd = ::accept(__fd, nullptr, 0);
@@ -1987,6 +2112,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                     } while (errno == ECONNABORTED && __connabort);
                   __ec.assign(errno, generic_category());
                   __h(__ec, socket_type(__ctx));
+#else
+                 __h(std::make_error_code(errc::operation_not_supported), 0);
+#endif
              });
          return __init.result.get();
        }
@@ -2012,6 +2140,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       socket_type
       accept(io_context& __ctx, endpoint_type& __endpoint, error_code& __ec)
       {
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
        do
          {
            socklen_t __len = __endpoint.capacity();
@@ -2024,6 +2153,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
              }
          } while (errno == ECONNABORTED && enable_connection_aborted());
        __ec.assign(errno, generic_category());
+#else
+       __ec = std::make_error_code(errc::operation_not_supported);
+#endif
        return socket_type{__ctx};
       }
 
@@ -2058,6 +2190,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                       __h(__ec, socket_type(__ctx));
                       return;
                     }
+#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
                   do
                     {
                       socklen_t __len = __ep.capacity();
@@ -2072,6 +2205,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                         }
                     } while (errno == ECONNABORTED && __connabort);
                   __ec.assign(errno, generic_category());
+#else
+                 __ec = std::make_error_code(errc::operation_not_supported);
+#endif
                   __h(__ec, socket_type(__ctx));
              });
          return __init.result.get();
@@ -2084,6 +2220,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       void
       wait(wait_type __w, error_code& __ec)
       {
+#ifdef _GLIBCXX_HAVE_POLL_H
        ::pollfd __fds;
        __fds.fd = native_handle();
        __fds.events = __w; // __w | POLLIN;
@@ -2091,6 +2228,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          __ec.assign(errno, generic_category());
        else
          __ec.clear();
+#else
+       __ec = std::make_error_code(errc::operation_not_supported);
+#endif
       }
 
       template<class _CompletionToken>