From 82a0f2fd10250b8129fd8a1c434b9e7dcf696bea Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 16 Oct 2018 17:12:32 +0100 Subject: [PATCH] Use autoconf to check for features needed by Networking TS * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Check for headers used by Networking TS. * include/experimental/executor: Include instead of . * include/experimental/internet: Use autoconf macros for available headers. Include for. Remove 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 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 | 44 +++++ libstdc++-v3/config.h.in | 18 +++ libstdc++-v3/configure | 16 ++ libstdc++-v3/configure.ac | 3 + libstdc++-v3/include/experimental/executor | 2 +- libstdc++-v3/include/experimental/internet | 67 +++++--- libstdc++-v3/include/experimental/io_context | 14 +- libstdc++-v3/include/experimental/socket | 162 +++++++++++++++++-- 8 files changed, 290 insertions(+), 36 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index a836ec58f45..681e88cb3a2 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,49 @@ 2018-10-16 Jonathan Wakely + * config.h.in: Regenerate. + * configure: Regenerate. + * configure.ac: Check for headers used by Networking TS. + * include/experimental/executor: Include + instead of . + * include/experimental/internet: Use autoconf macros for available + headers. Include for. Remove 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 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. diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in index 65e7b46dc4e..fa69b7a0895 100644 --- a/libstdc++-v3/config.h.in +++ b/libstdc++-v3/config.h.in @@ -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 header file. */ +#undef HAVE_ARPA_INET_H + /* Define to 1 if you have the `asinf' function. */ #undef HAVE_ASINF @@ -318,6 +321,15 @@ /* Define to 1 if you have the header file. */ #undef HAVE_NAN_H +/* Define to 1 if you have the header file. */ +#undef HAVE_NETDB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_IN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_TCP_H + /* Define if defines obsolete isinf function. */ #undef HAVE_OBSOLETE_ISINF @@ -327,6 +339,9 @@ /* Define if poll is available in . */ #undef HAVE_POLL +/* Define to 1 if you have the header file. */ +#undef HAVE_POLL_H + /* Define to 1 if you have the `posix_memalign' function. */ #undef HAVE_POSIX_MEMALIGN @@ -448,6 +463,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_SEM_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SOCKET_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STATVFS_H diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index 93a727e7cff..12a6d4cf0ef 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -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 diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index e3612b036df..dbb7dbc137c 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -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 diff --git a/libstdc++-v3/include/experimental/executor b/libstdc++-v3/include/experimental/executor index cd4adb58b0d..db8df4b871b 100644 --- a/libstdc++-v3/include/experimental/executor +++ b/libstdc++-v3/include/experimental/executor @@ -34,10 +34,10 @@ #if __cplusplus >= 201402L #include +#include #include #include #include -#include #include #include #include diff --git a/libstdc++-v3/include/experimental/internet b/libstdc++-v3/include/experimental/internet index 07fe6140f30..402a0474a95 100644 --- a/libstdc++-v3/include/experimental/internet +++ b/libstdc++-v3/include/experimental/internet @@ -34,19 +34,28 @@ #if __cplusplus >= 201402L #include +#include +#include #include #include #include -#include -#include #include -#include -#include #include -#include -#include -#include -#include +#ifdef _GLIBCXX_HAVE_UNISTD_H +# include +#endif +#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H +# include // AF_INET, AF_INET6, SOCK_DGRAM, SOCK_STREAM +#endif +#ifdef _GLIBCXX_HAVE_ARPA_INET_H +# include // inet_ntop +#endif +#ifdef _GLIBCXX_HAVE_NETINET_TCP_H +# include // TCP_NODELAY +#endif +#ifdef _GLIBCXX_HAVE_NETDB_H +# include // 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(__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> __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> __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 acceptor; ///< A TCP acceptor. typedef basic_socket_iostream 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 { @@ -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: diff --git a/libstdc++-v3/include/experimental/io_context b/libstdc++-v3/include/experimental/io_context index 7b42442a034..b8d231f7e68 100644 --- a/libstdc++-v3/include/experimental/io_context +++ b/libstdc++-v3/include/experimental/io_context @@ -41,9 +41,15 @@ #include #include #include -#include -#include -#include +#if _GLIBCXX_HAVE_UNISTD_H +# include +#endif +#ifdef _GLIBCXX_HAVE_POLL_H +# include +#endif +#ifdef _GLIBCXX_HAVE_FCNTL_H +# include +#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 }; diff --git a/libstdc++-v3/include/experimental/socket b/libstdc++-v3/include/experimental/socket index e92a4374db9..e903eb824b2 100644 --- a/libstdc++-v3/include/experimental/socket +++ b/libstdc++-v3/include/experimental/socket @@ -42,11 +42,21 @@ #include #if _GLIBCXX_HAVE_UNISTD_H # include -# include -# include -# include -# include -# include +# ifdef _GLIBCXX_HAVE_SYS_SOCKET_H +# include // socket etc +# endif +# ifdef _GLIBCXX_HAVE_SYS_IOCTL_H +# include // ioctl +# endif +# ifdef _GLIBCXX_HAVE_SYS_UIO_H +# include // iovec +# endif +# ifdef _GLIBCXX_HAVE_POLL_H +# include // poll, pollfd, POLLIN, POLLOUT, POLLERR +# endif +# ifdef _GLIBCXX_HAVE_FCNTL_H +# include // 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 { 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(__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 @@ -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(__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 @@ -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(__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 @@ -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(__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 @@ -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(__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 @@ -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(__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 @@ -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(__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(__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