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 <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
This commit is contained in:
Jonathan Wakely 2018-10-16 17:12:32 +01:00 committed by Jonathan Wakely
parent 7e8b87e901
commit 82a0f2fd10
8 changed files with 290 additions and 36 deletions

View 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.

View 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
@ -318,6 +321,15 @@
/* 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
@ -327,6 +339,9 @@
/* 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
@ -448,6 +463,9 @@
/* 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

View File

@ -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

View 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

View File

@ -34,10 +34,10 @@
#if __cplusplus >= 201402L
#include <algorithm>
#include <condition_variable>
#include <functional>
#include <future>
#include <list>
#include <mutex>
#include <queue>
#include <thread>
#include <tuple>

View File

@ -34,19 +34,28 @@
#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:

View File

@ -41,9 +41,15 @@
#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
};

View File

@ -42,11 +42,21 @@
#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>