diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2021-08-26 12:06:55 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2021-08-26 12:41:28 +0100 |
commit | cd67d138ec6006d650d1ba96c8a1322b285723cd (patch) | |
tree | 886adb8089eadb3fb25be227526f90ca9e12de82 /libstdc++-v3/include/experimental | |
parent | e370a2482d41fd382055695b9a0a638ce75e1038 (diff) |
libstdc++: Make Networking TS headers more portable [PR100285]
Add more preprocessor conditions to check for constants being defined
before using them, so that the Networking TS headers can be compiled on
a wider range of platforms.
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:
PR libstdc++/100285
* configure.ac: Check for O_NONBLOCK.
* configure: Regenerate.
* include/experimental/internet: Include <ws2tcpip.h> for
Windows. Use preprocessor conditions around more constants.
* include/experimental/socket: Use preprocessor conditions
around more constants.
* testsuite/experimental/net/internet/resolver/base.cc: Only use
constants when the corresponding C macro is defined.
* testsuite/experimental/net/socket/basic_socket.cc: Likewise.
* testsuite/experimental/net/socket/socket_base.cc: Likewise.
Make preprocessor checks more fine-grained.
Diffstat (limited to 'libstdc++-v3/include/experimental')
-rw-r--r-- | libstdc++-v3/include/experimental/internet | 16 | ||||
-rw-r--r-- | libstdc++-v3/include/experimental/socket | 22 |
2 files changed, 33 insertions, 5 deletions
diff --git a/libstdc++-v3/include/experimental/internet b/libstdc++-v3/include/experimental/internet index f6d6ef34504..6ce070ae775 100644 --- a/libstdc++-v3/include/experimental/internet +++ b/libstdc++-v3/include/experimental/internet @@ -61,6 +61,10 @@ # include <netdb.h> // getaddrinfo etc. #endif +#if defined _WIN32 && __has_include(<ws2tcpip.h>) +# include <ws2tcpip.h> +#endif + namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -263,7 +267,11 @@ namespace ip _S_ntoh_32(uint32_t __n) { return __builtin_bswap32(__n); } #endif +#ifdef _GLIBCXX_HAVE_ARPA_INET_H in_addr_t _M_addr; // network byte order +#else + uint32_t _M_addr; +#endif }; /// An IPv6 address. @@ -705,7 +713,7 @@ namespace ip inline address_v4 make_address_v4(string_view __str, error_code& __ec) noexcept { - char __buf[INET_ADDRSTRLEN]; + char __buf[16]; // INET_ADDRSTRLEN isn't defined on Windows auto __len = __str.copy(__buf, sizeof(__buf)); if (__len == sizeof(__buf)) { @@ -1686,9 +1694,15 @@ namespace ip #ifdef AI_NUMERICSERV static constexpr flags numeric_service = (flags)AI_NUMERICSERV; #endif +#ifdef AI_V4MAPPED static constexpr flags v4_mapped = (flags)AI_V4MAPPED; +#endif +#ifdef AI_ALL static constexpr flags all_matching = (flags)AI_ALL; +#endif +#ifdef AI_ADDRCONFIG static constexpr flags address_configured = (flags)AI_ADDRCONFIG; +#endif friend constexpr flags operator&(flags __f1, flags __f2) noexcept diff --git a/libstdc++-v3/include/experimental/socket b/libstdc++-v3/include/experimental/socket index 6d1c114254a..94241649777 100644 --- a/libstdc++-v3/include/experimental/socket +++ b/libstdc++-v3/include/experimental/socket @@ -293,11 +293,14 @@ inline namespace v1 static const int _S_level = SOL_SOCKET; static const int _S_name = SO_SNDLOWAT; }; +#endif // HAVE_SYS_SOCKET_H enum shutdown_type : int { }; +#if defined SHUT_RD && defined SHUT_WR && defined SHUT_RDWR static constexpr shutdown_type shutdown_receive = (shutdown_type)SHUT_RD; static constexpr shutdown_type shutdown_send = (shutdown_type)SHUT_WR; static constexpr shutdown_type shutdown_both = (shutdown_type)SHUT_RDWR; +#endif enum wait_type : int { }; #ifdef _GLIBCXX_HAVE_POLL_H @@ -311,14 +314,20 @@ inline namespace v1 #endif enum message_flags : int { }; +#if defined MSG_PEEK && defined MSG_OOB && defined MSG_DONTROUTE static constexpr message_flags message_peek = (message_flags)MSG_PEEK; static constexpr message_flags message_out_of_band = (message_flags)MSG_OOB; static constexpr message_flags message_do_not_route = (message_flags)MSG_DONTROUTE; +#endif - static const int max_listen_connections = SOMAXCONN; +#ifdef SOMAXCONN + static constexpr int max_listen_connections = SOMAXCONN; +#else + static constexpr int max_listen_connections = 4; +#endif // message_flags bitmask operations are defined as hidden friends. @@ -350,6 +359,7 @@ inline namespace v1 operator^=(message_flags& __f1, message_flags __f2) noexcept { return __f1 = (__f1 ^ __f2); } +#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H protected: struct __msg_hdr : ::msghdr { @@ -483,7 +493,7 @@ inline namespace v1 void native_non_blocking(bool __mode, error_code& __ec) { -#ifdef _GLIBCXX_HAVE_FCNTL_H +#if defined _GLIBCXX_HAVE_FCNTL_H && defined _GLIBCXX_HAVE_DECL_O_NONBLOCK int __flags = ::fcntl(_M_sockfd, F_GETFL, 0); if (__flags >= 0) { @@ -508,7 +518,7 @@ inline namespace v1 bool native_non_blocking() const { -#ifdef _GLIBCXX_HAVE_FCNTL_H +#if defined _GLIBCXX_HAVE_FCNTL_H && defined _GLIBCXX_HAVE_DECL_O_NONBLOCK if (_M_bits.native_non_blocking == -1) { const int __flags = ::fcntl(_M_sockfd, F_GETFL, 0); @@ -714,7 +724,9 @@ inline namespace v1 { error_code __ec; cancel(__ec); +#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H set_option(socket_base::linger{false, chrono::seconds{}}, __ec); +#endif ::close(_M_sockfd); } } @@ -1892,11 +1904,13 @@ inline namespace v1 { open(__protocol); } basic_socket_acceptor(io_context& __ctx, const endpoint_type& __endpoint, - bool __reuse_addr = true) + [[__maybe_unused__]] bool __reuse_addr = true) : basic_socket_acceptor(__ctx, __endpoint.protocol()) { +#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H if (__reuse_addr) set_option(reuse_address(true)); +#endif bind(__endpoint); listen(); } |