Commit e5989e71 by Jonathan Wakely Committed by Jonathan Wakely

Initial commit of Networking TS implementation

	* include/Makefile.am: Add new headers.
	* include/Makefile.in: Regenerate.
	* include/experimental/bits/net.h: New header for common
	implementation details of Networking TS.
	* include/experimental/buffer: New header.
	* include/experimental/executor: New header.
	* include/experimental/internet: New header.
	* include/experimental/io_context: New header.
	* include/experimental/net: New header.
	* include/experimental/netfwd: New header.
	* include/experimental/socket: New header.
	* include/experimental/timer: New header.
	* testsuite/experimental/net/buffer/arithmetic.cc: New test.
	* testsuite/experimental/net/buffer/const.cc: New test.
	* testsuite/experimental/net/buffer/creation.cc: New test.
	* testsuite/experimental/net/buffer/mutable.cc: New test.
	* testsuite/experimental/net/buffer/size.cc: New test.
	* testsuite/experimental/net/buffer/traits.cc: New test.
	* testsuite/experimental/net/execution_context/use_service.cc: New
	test.
	* testsuite/experimental/net/headers.cc: New test.
	* testsuite/experimental/net/internet/address/v4/comparisons.cc: New
	test.
	* testsuite/experimental/net/internet/address/v4/cons.cc: New test.
	* testsuite/experimental/net/internet/address/v4/creation.cc: New
	test.
	* testsuite/experimental/net/internet/address/v4/members.cc: New
	test.
	* testsuite/experimental/net/internet/resolver/base.cc: New test.
	* testsuite/experimental/net/internet/resolver/ops/lookup.cc: New
	test.
	* testsuite/experimental/net/internet/resolver/ops/reverse.cc: New
	test.
	* testsuite/experimental/net/timer/waitable/cons.cc: New test.
	* testsuite/experimental/net/timer/waitable/dest.cc: New test.
	* testsuite/experimental/net/timer/waitable/ops.cc: New test.

From-SVN: r265080
parent 0cfc095c
2018-10-12 Jonathan Wakely <jwakely@redhat.com>
Initial commit of Networking TS implementation.
* include/Makefile.am: Add new headers.
* include/Makefile.in: Regenerate.
* include/experimental/bits/net.h: New header for common
implementation details of Networking TS.
* include/experimental/buffer: New header.
* include/experimental/executor: New header.
* include/experimental/internet: New header.
* include/experimental/io_context: New header.
* include/experimental/net: New header.
* include/experimental/netfwd: New header.
* include/experimental/socket: New header.
* include/experimental/timer: New header.
* testsuite/experimental/net/buffer/arithmetic.cc: New test.
* testsuite/experimental/net/buffer/const.cc: New test.
* testsuite/experimental/net/buffer/creation.cc: New test.
* testsuite/experimental/net/buffer/mutable.cc: New test.
* testsuite/experimental/net/buffer/size.cc: New test.
* testsuite/experimental/net/buffer/traits.cc: New test.
* testsuite/experimental/net/execution_context/use_service.cc: New
test.
* testsuite/experimental/net/headers.cc: New test.
* testsuite/experimental/net/internet/address/v4/comparisons.cc: New
test.
* testsuite/experimental/net/internet/address/v4/cons.cc: New test.
* testsuite/experimental/net/internet/address/v4/creation.cc: New
test.
* testsuite/experimental/net/internet/address/v4/members.cc: New
test.
* testsuite/experimental/net/internet/resolver/base.cc: New test.
* testsuite/experimental/net/internet/resolver/ops/lookup.cc: New
test.
* testsuite/experimental/net/internet/resolver/ops/reverse.cc: New
test.
* testsuite/experimental/net/timer/waitable/cons.cc: New test.
* testsuite/experimental/net/timer/waitable/dest.cc: New test.
* testsuite/experimental/net/timer/waitable/ops.cc: New test.
PR libstdc++/77691
* include/experimental/memory_resource (__resource_adaptor_imp): Do
not allocate sizes smaller than alignment when relying on guaranteed
......
......@@ -671,15 +671,21 @@ experimental_headers = \
${experimental_srcdir}/algorithm \
${experimental_srcdir}/any \
${experimental_srcdir}/array \
${experimental_srcdir}/buffer \
${experimental_srcdir}/chrono \
${experimental_srcdir}/deque \
${experimental_srcdir}/executor \
${experimental_srcdir}/forward_list \
${experimental_srcdir}/functional \
${experimental_srcdir}/internet \
${experimental_srcdir}/io_context \
${experimental_srcdir}/iterator \
${experimental_srcdir}/list \
${experimental_srcdir}/map \
${experimental_srcdir}/memory \
${experimental_srcdir}/memory_resource \
${experimental_srcdir}/net \
${experimental_srcdir}/netfwd \
${experimental_srcdir}/numeric \
${experimental_srcdir}/optional \
${experimental_srcdir}/propagate_const \
......@@ -687,10 +693,12 @@ experimental_headers = \
${experimental_srcdir}/ratio \
${experimental_srcdir}/regex \
${experimental_srcdir}/set \
${experimental_srcdir}/socket \
${experimental_srcdir}/source_location \
${experimental_srcdir}/string \
${experimental_srcdir}/string_view \
${experimental_srcdir}/system_error \
${experimental_srcdir}/timer \
${experimental_srcdir}/tuple \
${experimental_srcdir}/type_traits \
${experimental_srcdir}/unordered_map \
......@@ -704,6 +712,7 @@ experimental_bits_builddir = ./experimental/bits
experimental_bits_headers = \
${experimental_bits_srcdir}/erase_if.h \
${experimental_bits_srcdir}/lfts_config.h \
${experimental_bits_srcdir}/net.h \
${experimental_bits_srcdir}/shared_ptr.h \
${experimental_bits_srcdir}/string_view.tcc \
${experimental_bits_filesystem_headers}
......
......@@ -963,15 +963,21 @@ experimental_headers = \
${experimental_srcdir}/algorithm \
${experimental_srcdir}/any \
${experimental_srcdir}/array \
${experimental_srcdir}/buffer \
${experimental_srcdir}/chrono \
${experimental_srcdir}/deque \
${experimental_srcdir}/executor \
${experimental_srcdir}/forward_list \
${experimental_srcdir}/functional \
${experimental_srcdir}/internet \
${experimental_srcdir}/io_context \
${experimental_srcdir}/iterator \
${experimental_srcdir}/list \
${experimental_srcdir}/map \
${experimental_srcdir}/memory \
${experimental_srcdir}/memory_resource \
${experimental_srcdir}/net \
${experimental_srcdir}/netfwd \
${experimental_srcdir}/numeric \
${experimental_srcdir}/optional \
${experimental_srcdir}/propagate_const \
......@@ -979,10 +985,12 @@ experimental_headers = \
${experimental_srcdir}/ratio \
${experimental_srcdir}/regex \
${experimental_srcdir}/set \
${experimental_srcdir}/socket \
${experimental_srcdir}/source_location \
${experimental_srcdir}/string \
${experimental_srcdir}/string_view \
${experimental_srcdir}/system_error \
${experimental_srcdir}/timer \
${experimental_srcdir}/tuple \
${experimental_srcdir}/type_traits \
${experimental_srcdir}/unordered_map \
......@@ -996,6 +1004,7 @@ experimental_bits_builddir = ./experimental/bits
experimental_bits_headers = \
${experimental_bits_srcdir}/erase_if.h \
${experimental_bits_srcdir}/lfts_config.h \
${experimental_bits_srcdir}/net.h \
${experimental_bits_srcdir}/shared_ptr.h \
${experimental_bits_srcdir}/string_view.tcc \
${experimental_bits_filesystem_headers}
......
// Networking implementation details -*- C++ -*-
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file experimental/bits/net.h
* This is an internal header file, included by other library headers.
* Do not attempt to use it directly. @headername{experimental/networking}
*/
#ifndef _GLIBCXX_EXPERIMENTAL_NET_H
#define _GLIBCXX_EXPERIMENTAL_NET_H 1
#pragma GCC system_header
#if __cplusplus >= 201402L
#include <type_traits>
#include <system_error>
#include <experimental/netfwd>
namespace std _GLIBCXX_VISIBILITY(default)
{
namespace experimental
{
namespace net
{
inline namespace v1
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* @ingroup networking
* @{
*/
template<typename _CompletionToken, typename _Signature, typename>
class async_result;
// A type denoted by DEDUCED in the TS.
template<typename _CompletionToken, typename _Signature>
using __deduced_t = typename
async_result<decay_t<_CompletionToken>, _Signature, void>::return_type;
// Trait to check for construction from const/non-const lvalue/rvalue.
template<typename _Tp>
using __is_value_constructible = typename __and_<
is_copy_constructible<_Tp>, is_move_constructible<_Tp>,
is_constructible<_Tp, _Tp&>, is_constructible<_Tp, const _Tp&&>
>::type;
struct __throw_on_error
{
explicit
__throw_on_error(const char* __msg) : _M_msg(__msg) { }
~__throw_on_error() noexcept(false)
{
if (_M_ec)
_GLIBCXX_THROW_OR_ABORT(system_error(_M_ec, _M_msg));
}
__throw_on_error(const __throw_on_error&) = delete;
__throw_on_error& operator=(const __throw_on_error&) = delete;
operator error_code&() noexcept { return _M_ec; }
const char* _M_msg;
error_code _M_ec;
};
// Base class for types meeting IntegerSocketOption requirements.
template<typename _Tp>
struct __sockopt_base
{
__sockopt_base() = default;
explicit __sockopt_base(int __val) : _M_value(__val) { }
int value() const noexcept { return _M_value; }
template<typename _Protocol>
void*
data(const _Protocol&) noexcept
{ return std::addressof(_M_value); }
template<typename _Protocol>
const void*
data(const _Protocol&) const noexcept
{ return std::addressof(_M_value); }
template<typename _Protocol>
size_t
size(const _Protocol&) const noexcept
{ return sizeof(_M_value); }
template<typename _Protocol>
void
resize(const _Protocol&, size_t __s)
{
if (__s != sizeof(_M_value))
__throw_length_error("invalid value for socket option resize");
}
protected:
_Tp _M_value { };
};
// Base class for types meeting BooleanSocketOption requirements.
template<>
struct __sockopt_base<bool> : __sockopt_base<int>
{
__sockopt_base() = default;
explicit __sockopt_base(bool __val) : __sockopt_base<int>(__val) { }
bool value() const noexcept { return __sockopt_base<int>::_M_value; }
explicit operator bool() const noexcept { return value(); }
bool operator!() const noexcept { return !value(); }
};
template<typename _Derived, typename _Tp = int>
struct __sockopt_crtp : __sockopt_base<_Tp>
{
using __sockopt_base<_Tp>::__sockopt_base;
_Derived&
operator=(_Tp __value)
{
__sockopt_base<_Tp>::_M_value = __value;
return static_cast<_Derived&>(*this);
}
template<typename _Protocol>
int
level(const _Protocol&) const noexcept
{ return _Derived::_S_level; }
template<typename _Protocol>
int
name(const _Protocol&) const noexcept
{ return _Derived::_S_name; }
};
/// @}
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace v1
} // namespace net
} // namespace experimental
} // namespace std
#endif // C++14
#endif // _GLIBCXX_EXPERIMENTAL_NET_H
// <experimental/net> -*- C++ -*-
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file experimental/net
* This is a TS C++ Library header.
*/
#ifndef _GLIBCXX_EXPERIMENTAL_NET
#define _GLIBCXX_EXPERIMENTAL_NET
#pragma GCC system_header
#if __cplusplus >= 201402L
#include <experimental/executor>
#include <experimental/io_context>
#include <experimental/timer>
#include <experimental/buffer>
#include <experimental/socket>
#include <experimental/internet>
#endif // C++14
#endif // _GLIBCXX_EXPERIMENTAL_NET
// <experimental/netfwd> -*- C++ -*-
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file experimental/netfwd
* This is a TS C++ Library header.
*/
#ifndef _GLIBCXX_EXPERIMENTAL_NETFWD
#define _GLIBCXX_EXPERIMENTAL_NETFWD 1
#pragma GCC system_header
#if __cplusplus >= 201402L
// #define __cpp_lib_experimental_net 201803
// #define __cpp_lib_experimental_net_extensible 201803
#include <chrono>
namespace std _GLIBCXX_VISIBILITY(default)
{
namespace experimental
{
namespace net
{
inline namespace v1
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* @ingroup networking
* @{
*/
class execution_context;
template<typename _Tp, typename _Executor>
class executor_binder;
template<typename _Executor>
class executor_work_guard;
class system_executor;
class executor;
template<typename _Executor>
class strand;
class io_service;
template<typename _Clock> struct wait_traits;
template<typename _Clock, typename _WaitTraits = wait_traits<_Clock>>
class basic_waitable_timer;
typedef basic_waitable_timer<chrono::system_clock> system_timer;
typedef basic_waitable_timer<chrono::steady_clock> steady_timer;
typedef basic_waitable_timer<chrono::high_resolution_clock>
high_resolution_timer;
template<typename _Protocol>
class basic_socket;
template<typename _Protocol>
class basic_datagram_socket;
template<typename _Protocol>
class basic_stream_socket;
template<typename _Protocol>
class basic_socket_acceptor;
template<typename _Protocol, typename _Clock = chrono::steady_clock,
typename _WaitTraits = wait_traits<_Clock>>
class basic_socket_streambuf;
template<typename _Protocol, typename _Clock = chrono::steady_clock,
typename _WaitTraits = wait_traits<_Clock>>
class basic_socket_iostream;
/// @}
_GLIBCXX_END_NAMESPACE_VERSION
namespace ip
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* @ingroup networking
* @{
*/
class address;
class address_v4;
class address_v6;
class address_iterator_v4;
class address_iterator_v6;
class address_range_v4;
class address_range_v6;
class network_v4;
class network_v6;
template<typename _InternetProtocol>
class basic_endpoint;
template<typename _InternetProtocol>
class basic_resolver_entry;
template<typename _InternetProtocol>
class basic_resolver_results;
template<typename _InternetProtocol>
class basic_resolver;
class tcp;
class udp;
/// @}
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace ip
} // namespace v1
} // namespace net
} // namespace experimental
} // namespace std
#endif // C++14
#endif // _GLIBCXX_EXPERIMENTAL_NETFWD
// <experimental/timer> -*- C++ -*-
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file experimental/timer
* This is a TS C++ Library header.
*/
#ifndef _GLIBCXX_EXPERIMENTAL_TIMER
#define _GLIBCXX_EXPERIMENTAL_TIMER 1
#pragma GCC system_header
#if __cplusplus >= 201402L
#include <chrono>
#include <system_error>
#include <thread>
#include <experimental/netfwd>
#include <experimental/io_context>
#include <experimental/bits/net.h>
namespace std _GLIBCXX_VISIBILITY(default)
{
namespace experimental
{
namespace net
{
inline namespace v1
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* @ingroup networking
* @{
*/
template<typename _Clock>
struct wait_traits
{
static typename _Clock::duration
to_wait_duration(const typename _Clock::duration& __d)
{ return __d; }
static typename _Clock::duration
to_wait_duration(const typename _Clock::time_point& __t)
{
auto __now = _Clock::now();
auto __diff = __t - __now;
if (__diff > _Clock::duration::max())
return _Clock::duration::max();
if (__diff < _Clock::duration::min())
return _Clock::duration::min();
return __diff;
}
};
template<typename _Clock, typename _WaitTraits>
class basic_waitable_timer
{
public:
// types:
typedef io_context::executor_type executor_type;
typedef _Clock clock_type;
typedef typename clock_type::duration duration;
typedef typename clock_type::time_point time_point;
typedef _WaitTraits traits_type;
// construct / copy / destroy:
explicit
basic_waitable_timer(io_context& __ctx)
: _M_ex(__ctx.get_executor()), _M_expiry()
{ }
basic_waitable_timer(io_context& __ctx, const time_point& __t)
: _M_ex(__ctx.get_executor()), _M_expiry(__t)
{ }
basic_waitable_timer(io_context& __ctx, const duration& __d)
: _M_ex(__ctx.get_executor()), _M_expiry(_Clock::now() + __d)
{ }
basic_waitable_timer(const basic_waitable_timer&) = delete;
basic_waitable_timer(basic_waitable_timer&& __rhs)
: _M_ex(std::move(__rhs._M_ex)), _M_expiry(__rhs._M_expiry)
{
_M_key.swap(__rhs._M_key);
__rhs._M_expiry = time_point{};
}
~basic_waitable_timer() { cancel(); }
basic_waitable_timer& operator=(const basic_waitable_timer&) = delete;
basic_waitable_timer&
operator=(basic_waitable_timer&& __rhs)
{
if (this == std::addressof(__rhs))
return *this;
cancel();
_M_ex = std::move(__rhs._M_ex);
_M_expiry = __rhs._M_expiry;
__rhs._M_expiry = time_point{};
_M_key.swap(__rhs._M_key);
return *this;
}
// basic_waitable_timer operations:
executor_type get_executor() noexcept { return _M_ex; }
size_t cancel() { return _M_ex.context().cancel(*this); }
size_t cancel_one() { return _M_ex.context().cancel_one(*this); }
time_point expiry() const { return _M_expiry; }
size_t expires_at(const time_point& __t)
{
size_t __cancelled = cancel();
_M_expiry = __t;
return __cancelled;
}
size_t expires_after(const duration& __d)
{ return expires_at(_Clock::now() + __d); }
void wait();
void wait(error_code& __ec);
template<typename _CompletionToken>
__deduced_t<_CompletionToken, void(error_code)>
async_wait(_CompletionToken&& __token)
{
async_completion<_CompletionToken, void(error_code)> __init(__token);
_M_ex.context().async_wait(*this,
std::move(__init.completion_handler));
return __init.result.get();
}
private:
executor_type _M_ex;
time_point _M_expiry;
struct _Key { }; // TODO move _M_expiry into here?
unique_ptr<_Key> _M_key{new _Key};
friend class io_context;
};
typedef basic_waitable_timer<chrono::system_clock> system_timer;
typedef basic_waitable_timer<chrono::steady_clock> steady_timer;
typedef basic_waitable_timer<chrono::high_resolution_clock>
high_resolution_timer;
template<typename _Clock, typename _WaitTraits>
void
basic_waitable_timer<_Clock, _WaitTraits>::wait()
{
_M_ex.dispatch([this] {
while (clock_type::now() < _M_expiry)
this_thread::sleep_for(traits_type::to_wait_duration(_M_expiry));
}, allocator<void>{});
}
template<typename _Clock, typename _WaitTraits>
void
basic_waitable_timer<_Clock, _WaitTraits>::wait(error_code&)
{
_M_ex.dispatch([this] {
while (clock_type::now() < _M_expiry)
this_thread::sleep_for(traits_type::to_wait_duration(_M_expiry));
}, allocator<void>{});
}
/// @}
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace v1
} // namespace net
} // namespace experimental
} // namespace std
#endif // C++14
#endif // _GLIBCXX_EXPERIMENTAL_TIMER
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/buffer>
#include <testsuite_hooks.h>
using std::experimental::net::mutable_buffer;
using std::experimental::net::const_buffer;
void
test01()
{
bool test __attribute__((unused)) = false;
char c[4];
mutable_buffer mb;
mb = mb + 0;
VERIFY( mb.data() == nullptr );
VERIFY( mb.size() == 0 );
mb = 0 + mb;
VERIFY( mb.data() == nullptr );
VERIFY( mb.size() == 0 );
mb = mutable_buffer(c, sizeof(c));
mb = mb + 1;
VERIFY( mb.data() == c+1 );
VERIFY( mb.size() == 3 );
mb = mb + 2;
VERIFY( mb.data() == c+3 );
VERIFY( mb.size() == 1 );
mb = mb + 2;
VERIFY( mb.data() == c+4 );
VERIFY( mb.size() == 0 );
mb = mutable_buffer(c, sizeof(c));
mb = 3 + mb;
VERIFY( mb.data() == c+3 );
VERIFY( mb.size() == 1 );
mb = 2 + mb;
VERIFY( mb.data() == c+4 );
VERIFY( mb.size() == 0 );
}
void
test02()
{
bool test __attribute__((unused)) = false;
char c[4];
const_buffer cb;
cb = cb + 0;
VERIFY( cb.data() == nullptr );
VERIFY( cb.size() == 0 );
cb = 0 + cb;
VERIFY( cb.data() == nullptr );
VERIFY( cb.size() == 0 );
cb = const_buffer(c, sizeof(c));
cb = cb + 1;
VERIFY( cb.data() == c+1 );
VERIFY( cb.size() == 3 );
cb = cb + 2;
VERIFY( cb.data() == c+3 );
VERIFY( cb.size() == 1 );
cb = cb + 2;
VERIFY( cb.data() == c+4 );
VERIFY( cb.size() == 0 );
cb = const_buffer(c, sizeof(c));
cb = 3 + cb;
VERIFY( cb.data() == c+3 );
VERIFY( cb.size() == 1 );
cb = 2 + cb;
VERIFY( cb.data() == c+4 );
VERIFY( cb.size() == 0 );
}
int
main()
{
test01();
test02();
}
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/buffer>
#include <testsuite_hooks.h>
using std::experimental::net::const_buffer;
using std::experimental::net::mutable_buffer;
void
test01()
{
using B = const_buffer;
const B b;
static_assert( std::is_nothrow_default_constructible<B>::value,
"const_mutable is nothrow default constructible" );
static_assert( std::is_copy_assignable<B>::value,
"const_mutable is copy assignable" );
static_assert( std::is_nothrow_constructible<B, const void*, size_t>::value,
"const_mutable is nothrow constructible from pointer and length" );
static_assert( std::is_nothrow_constructible<B, mutable_buffer>::value,
"const_mutable is nothrow constructible from mutable_buffer" );
static_assert( std::is_same<decltype(b.data()), const void*>::value,
"data() return const void*" );
static_assert( noexcept(b.data()),
"data() is nothrow" );
static_assert( std::is_same<decltype(b.size()), size_t>::value,
"size() return size_t" );
static_assert( noexcept(b.size()),
"size() is nothrow" );
}
void
test02()
{
bool test __attribute__((unused)) = false;
char c[4];
const_buffer b;
VERIFY( b.data() == nullptr );
VERIFY( b.size() == 0 );
b = const_buffer(c, sizeof(c));
VERIFY( b.data() == c );
VERIFY( b.size() == sizeof(c) );
b = const_buffer{};
VERIFY( b.data() == nullptr );
VERIFY( b.size() == 0 );
}
int
main()
{
test01();
test02();
}
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/buffer>
#include <testsuite_hooks.h>
namespace net = std::experimental::net;
template<typename T>
bool is_mutable(const T&)
{ return std::is_same<T, net::mutable_buffer>::value; }
template<typename T>
bool is_const(const T&)
{ return std::is_same<T, net::const_buffer>::value; }
void
test01()
{
bool test = false;
auto b1 = net::buffer((void*)&test, sizeof(test));
VERIFY( is_mutable(b1) );
VERIFY( b1.data() == &test );
VERIFY( b1.size() == sizeof(test) );
auto b2 = net::buffer((const void*)&test, sizeof(test));
VERIFY( is_const(b2) );
VERIFY( b2.data() == &test );
VERIFY( b1.size() == sizeof(test) );
auto b3 = net::buffer(b1);
VERIFY( is_mutable(b3) );
VERIFY( b3.data() == b1.data() );
VERIFY( b3.size() == b1.size() );
auto b4 = net::buffer(b2);
VERIFY( is_const(b4) );
VERIFY( b4.data() == b2.data() );
VERIFY( b4.size() == b2.size() );
auto b5 = net::buffer(b1, 0);
VERIFY( is_mutable(b5) );
VERIFY( b5.data() == b1.data() );
VERIFY( b5.size() == 0 );
auto b6 = net::buffer(b2, 0);
VERIFY( is_const(b6) );
VERIFY( b6.data() == b2.data() );
VERIFY( b6.size() == 0 );
int a7[7];
auto b7 = net::buffer(a7);
VERIFY( is_mutable(b7) );
VERIFY( b7.data() == a7 );
VERIFY( b7.size() == sizeof(a7) );
auto b7x = net::buffer(a7, 2);
VERIFY( is_mutable(b7x) );
VERIFY( b7x.data() == a7 );
VERIFY( b7x.size() == sizeof(a7[0]) * 2 );
const short a8[8] = { };
auto b8 = net::buffer(a8);
VERIFY( is_const(b8) );
VERIFY( b8.data() == a8 );
VERIFY( b8.size() == sizeof(a8) );
auto b8x = net::buffer(a8, 3);
VERIFY( is_const(b8x) );
VERIFY( b8x.data() == a8 );
VERIFY( b8x.size() == sizeof(a8[0]) * 3 );
std::array<short, 9> a9;
auto b9 = net::buffer(a9);
VERIFY( is_mutable(b9) );
VERIFY( b9.data() == a9.data() );
VERIFY( b9.size() == sizeof(a9) );
auto b9x = net::buffer(a9, 4);
VERIFY( is_mutable(b9x) );
VERIFY( b9x.data() == a9.data() );
VERIFY( b9x.size() == sizeof(a9[0]) * 4 );
const std::array<long long, 10> a10{};
auto b10 = net::buffer(a10);
VERIFY( is_const(b10) );
VERIFY( b10.data() == a10.data() );
VERIFY( b10.size() == sizeof(a10) );
auto b10x = net::buffer(a10, 5);
VERIFY( is_const(b10x) );
VERIFY( b10x.data() == a10.data() );
VERIFY( b10x.size() == sizeof(a10[0]) * 5 );
std::array<const int, 11> a11{};
auto b11 = net::buffer(a11);
VERIFY( is_const(b11) );
VERIFY( b11.data() == a11.data() );
VERIFY( b11.size() == sizeof(a11) );
auto b11x = net::buffer(a11, 6);
VERIFY( is_const(b11x) );
VERIFY( b11x.data() == a11.data() );
VERIFY( b11x.size() == sizeof(a11[0]) * 6 );
std::vector<short> a12(12);
auto b12 = net::buffer(a12);
VERIFY( is_mutable(b12) );
VERIFY( b12.data() == a12.data() );
VERIFY( b12.size() == sizeof(a12[0]) * a12.size() );
auto b12x = net::buffer(a12, 7);
VERIFY( is_mutable(b12x) );
VERIFY( b12x.data() == a12.data() );
VERIFY( b12x.size() == sizeof(a12[0]) * 7 );
const std::vector<long long> a13(13);
auto b13 = net::buffer(a13);
VERIFY( is_const(b13) );
VERIFY( b13.data() == a13.data() );
VERIFY( b13.size() == sizeof(a13[0]) * a13.size() );
auto b13x = net::buffer(a13, 7);
VERIFY( is_const(b13x) );
VERIFY( b13x.data() == a13.data() );
VERIFY( b13x.size() == sizeof(a13[0]) * 7 );
std::u32string a14(14, ' ');
auto b14 = net::buffer(a14);
VERIFY( is_mutable(b14) );
VERIFY( b14.data() == a14.data() );
VERIFY( b14.size() == sizeof(a14[0]) * a14.size() );
auto b14x = net::buffer(a14, 8);
VERIFY( is_mutable(b14x) );
VERIFY( b14x.data() == a14.data() );
VERIFY( b14x.size() == sizeof(a14[0]) * 8 );
const std::u16string a15(15, ' ');
auto b15 = net::buffer(std::experimental::u16string_view(a15));
VERIFY( is_const(b15) );
VERIFY( b15.data() == a15.data() );
VERIFY( b15.size() == sizeof(a15[0]) * a15.size() );
auto b15x = net::buffer(std::experimental::u16string_view(a15), 9);
VERIFY( is_const(b15x) );
VERIFY( b15x.data() == a15.data() );
VERIFY( b15x.size() == sizeof(a15[0]) * 9 );
}
int
main()
{
test01();
}
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/buffer>
#include <testsuite_hooks.h>
using std::experimental::net::mutable_buffer;
void
test01()
{
using B = mutable_buffer;
const B b;
static_assert( std::is_nothrow_default_constructible<B>::value,
"const_mutable is nothrow default constructible" );
static_assert( std::is_copy_assignable<B>::value,
"const_mutable is copy assignable" );
static_assert( std::is_nothrow_constructible<B, void*, size_t>::value,
"const_mutable is nothrow default constructible" );
static_assert( std::is_same<decltype(b.data()), void*>::value,
"data() return const void*" );
static_assert( noexcept(b.data()),
"data() is nothrow" );
static_assert( std::is_same<decltype(b.size()), size_t>::value,
"size() return size_t" );
static_assert( noexcept(b.size()),
"size() is nothrow" );
}
void
test02()
{
bool test __attribute__((unused)) = false;
char c[4];
mutable_buffer b;
VERIFY( b.data() == nullptr );
VERIFY( b.size() == 0 );
b = mutable_buffer(c, sizeof(c));
VERIFY( b.data() == c );
VERIFY( b.size() == sizeof(c) );
b = mutable_buffer{};
VERIFY( b.data() == nullptr );
VERIFY( b.size() == 0 );
}
int
main()
{
test01();
test02();
}
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/buffer>
#include <testsuite_hooks.h>
using std::experimental::net::const_buffer;
using std::experimental::net::mutable_buffer;
void
test01()
{
bool test __attribute__((unused)) = false;
char c[4];
mutable_buffer mb;
VERIFY( buffer_size(mb) == 0 );
mb = mutable_buffer(c, sizeof(c));
VERIFY( buffer_size(mb) == mb.size() );
const_buffer cb;
VERIFY( buffer_size(cb) == 0 );
cb = const_buffer(c, sizeof(c));
VERIFY( buffer_size(cb) == cb.size() );
}
void
test02()
{
bool test __attribute__((unused)) = false;
char c[32];
std::vector<mutable_buffer> mv{ {c, 0}, {c, 32}, {c, 16}, {c, 3}, {c, 0} };
VERIFY( buffer_size(mv) == (0 + 32 + 16 + 3 + 0) );
std::vector<const_buffer> cv{ {c, 0}, {c, 32}, {c, 16}, {c, 3}, {c, 0} };
VERIFY( buffer_size(cv) == (0 + 32 + 16 + 3 + 0) );
}
int
main()
{
test01();
test02();
}
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
// { dg-do compile }
#include <experimental/buffer>
using namespace std::experimental::net;
using std::vector;
using std::string;
using std::char_traits;
using std::allocator;
template<typename T>
struct Seq {
struct Buf {
operator T() const { return {}; }
};
Buf* begin() const { return nullptr; }
Buf* end() const { return nullptr; }
};
static_assert( is_mutable_buffer_sequence<mutable_buffer>::value,
"mutable_buffer is a mutable buffer sequence" );
static_assert( is_mutable_buffer_sequence<const mutable_buffer>::value,
"const mutable_buffer is a mutable buffer sequence" );
static_assert( is_mutable_buffer_sequence<vector<mutable_buffer>>::value,
"vector<mutable_buffer> is a mutable buffer sequence" );
static_assert( is_mutable_buffer_sequence<const vector<mutable_buffer>>::value,
"const vector<mutable_buffer> is a mutable buffer sequence" );
static_assert( is_mutable_buffer_sequence<Seq<mutable_buffer>>::value,
"Seq<mutable_buffer> is a mutable buffer sequence" );
static_assert( is_mutable_buffer_sequence<const Seq<mutable_buffer>>::value,
"const Seq<mutable_buffer> is a mutable buffer sequence" );
static_assert( is_mutable_buffer_sequence<Seq<const mutable_buffer>>::value,
"Seq<const mutable_buffer> is a mutable buffer sequence" );
static_assert( ! is_mutable_buffer_sequence<const_buffer>::value,
"const_buffer is not a mutable buffer sequence" );
static_assert( ! is_mutable_buffer_sequence<vector<const_buffer>>::value,
"vector<const_buffer> is not a mutable buffer sequence" );
static_assert( ! is_mutable_buffer_sequence<Seq<const_buffer>>::value,
"Seq<const_buffer> is not a mutable buffer sequence" );
static_assert( is_const_buffer_sequence<const_buffer>::value,
"const_buffer is a const buffer sequence" );
static_assert( is_const_buffer_sequence<const const_buffer>::value,
"const const_buffer is a const buffer sequence" );
static_assert( is_const_buffer_sequence<vector<const_buffer>>::value,
"vector<const_buffer> is a const buffer sequence" );
static_assert( is_const_buffer_sequence<const vector<const_buffer>>::value,
"const vector<const_buffer> is a const buffer sequence" );
static_assert( is_const_buffer_sequence<Seq<const_buffer>>::value,
"Seq<const_buffer> is a const buffer sequence" );
static_assert( is_const_buffer_sequence<const Seq<const_buffer>>::value,
"const Seq<const_buffer> is a const buffer sequence" );
static_assert( is_const_buffer_sequence<Seq<const const_buffer>>::value,
"Seq<const const_buffer> is a const buffer sequence" );
static_assert( is_const_buffer_sequence<mutable_buffer>::value,
"mutable_buffer is a const buffer sequence" );
static_assert( is_const_buffer_sequence<const mutable_buffer>::value,
"const mutable_buffer is a const buffer sequence" );
static_assert( is_const_buffer_sequence<vector<mutable_buffer>>::value,
"vector<mutable_buffer> is a const buffer sequence" );
static_assert( is_const_buffer_sequence<const vector<mutable_buffer>>::value,
"const vector<mutable_buffer> is a const buffer sequence" );
// Buf -> mutable_buffer -> const_buffer needs two user-defined conversions:
static_assert( ! is_const_buffer_sequence<Seq<mutable_buffer>>::value,
"Seq<mutable_buffer> is not a const buffer sequence" );
static_assert( is_dynamic_buffer<
dynamic_vector_buffer<int, allocator<int>>
>::value, "dynamic_vector_buffer is a dynamic buffer" );
static_assert( is_dynamic_buffer<
dynamic_string_buffer<char, char_traits<char>, allocator<int>>
>::value, "dynamic_string_buffer is a dynamic buffer" );
static_assert( ! is_dynamic_buffer<vector<int>>::value,
"vector is not a dynamic buffer" );
static_assert( ! is_dynamic_buffer<string>::value,
"string is not a dynamic buffer" );
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/executor>
#include <testsuite_hooks.h>
using std::experimental::net::execution_context;
using std::experimental::net::use_service;
struct service1 : execution_context::service
{
using key_type = service1;
service1(execution_context& c) : service(c) { }
void shutdown() noexcept { }
};
struct key2 : execution_context::service
{
key2(execution_context& c) : service(c) { }
};
struct service2 : key2
{
using key_type = key2;
service2(execution_context& c) : key2(c) { }
void shutdown() noexcept { }
};
struct service3 : service1
{
using service1::service1;
};
struct service4 : service2
{
using service2::service2;
};
void
test01()
{
execution_context ctx;
service1& svc1 = use_service<service1>(ctx);
service1& svc1a = use_service<service1>(ctx);
VERIFY( &svc1a == &svc1 );
key2& svc2 = use_service<service2>(ctx);
key2& svc2a = use_service<service2>(ctx);
VERIFY( &svc2a == &svc2 );
service1& svc3 = use_service<service3>(ctx);
VERIFY( &svc3 == &svc1 );
key2& svc4 = use_service<service4>(ctx);
VERIFY( &svc4 == &svc2 );
// TODO test02() function that puts derived types in first, then tests base comes out
}
int
main()
{
test01();
}
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
// { dg-do compile }
#include <experimental/net>
// Re-include:
#include <experimental/buffer>
#include <experimental/executor>
#include <experimental/internet>
#include <experimental/io_context>
#include <experimental/netfwd>
#include <experimental/socket>
#include <experimental/timer>
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/internet>
#include <testsuite_hooks.h>
using std::experimental::net::ip::address_v4;
void
test01()
{
bool test __attribute__((unused)) = false;
address_v4 addrs[] = {
address_v4::any(), address_v4::loopback(), address_v4::broadcast(),
address_v4{0x11001100}, address_v4{0xEFEFEFEF}
};
auto begin = std::begin(addrs);
auto end = std::end(addrs);
for (auto it = begin; it != end; ++it)
{
auto& a = *it;
VERIFY( a == a );
VERIFY( a <= a );
VERIFY( a >= a );
VERIFY( ! (a != a) );
VERIFY( ! (a < a) );
VERIFY( ! (a > a) );
}
std::sort(begin, end);
for (auto it = begin + 1; it != end; ++it)
{
auto& a = *it;
auto& b = *begin;
VERIFY( ! (a == b) );
VERIFY( a != b );
VERIFY( b < a );
VERIFY( b <= a );
VERIFY( a > b );
VERIFY( a >= b );
}
}
int
main()
{
test01();
}
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/internet>
#include <testsuite_hooks.h>
using std::experimental::net::ip::address_v4;
void
test01()
{
bool test __attribute__((unused)) = false;
address_v4 a0;
VERIFY( a0.to_uint() == 0 );
VERIFY( a0.to_bytes() == address_v4::bytes_type{} );
}
void
test02()
{
bool test __attribute__((unused)) = false;
address_v4 a0{ address_v4::bytes_type{} };
VERIFY( a0.to_uint() == 0 );
VERIFY( a0.to_bytes() == address_v4::bytes_type{} );
address_v4::bytes_type b1{ 1, 2, 3, 4 };
address_v4 a1{ b1 };
VERIFY( a1.to_uint() == ntohl((1 << 24) | (2 << 16) | (3 << 8) | 4) );
VERIFY( a1.to_bytes() == b1 );
}
void
test03()
{
bool test __attribute__((unused)) = false;
address_v4 a0{ 0u };
VERIFY( a0.to_uint() == 0 );
VERIFY( a0.to_bytes() == address_v4::bytes_type{} );
address_v4::uint_type u1 = ntohl((5 << 24) | (6 << 16) | (7 << 8) | 8);
address_v4 a1{ u1 };
VERIFY( a1.to_uint() == u1 );
VERIFY( a1.to_bytes() == address_v4::bytes_type( 5, 6, 7, 8 ) );
}
int
main()
{
test01();
test02();
test03();
}
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/internet>
#include <testsuite_hooks.h>
namespace ip = std::experimental::net::ip;
using ip::address_v4;
void
test01()
{
bool test __attribute__((unused)) = false;
auto a0 = make_address_v4( address_v4::bytes_type{} );
VERIFY( a0.to_uint() == 0 );
VERIFY( a0.to_bytes() == address_v4::bytes_type{} );
address_v4::bytes_type b1{ 1, 2, 3, 4 };
auto a1 = make_address_v4( b1 );
VERIFY( a1.to_uint() == ntohl((1 << 24) | (2 << 16) | (3 << 8) | 4) );
VERIFY( a1.to_bytes() == b1 );
}
void
test02()
{
bool test __attribute__((unused)) = false;
auto a0 = ip::make_address_v4(0u);
VERIFY( a0.to_uint() == 0 );
VERIFY( a0.to_bytes() == address_v4::bytes_type{} );
address_v4::uint_type u1 = ntohl((5 << 24) | (6 << 16) | (7 << 8) | 8);
auto a1 = ip::make_address_v4( u1 );
VERIFY( a1.to_uint() == u1 );
VERIFY( a1.to_bytes() == address_v4::bytes_type( 5, 6, 7, 8 ) );
}
void
test03()
{
bool test __attribute__((unused)) = false;
auto a1 = ip::make_address_v4("127.0.0.1");
VERIFY( a1.is_loopback() );
auto a2 = ip::make_address_v4(std::string{"127.0.0.2"});
VERIFY( a2.is_loopback() );
auto a3 = ip::make_address_v4(std::experimental::string_view{"127.0.0.3"});
VERIFY( a3.is_loopback() );
std::error_code ec;
auto a4 = ip::make_address_v4("127...1", ec);
VERIFY( ec == std::errc::invalid_argument );
ip::make_address_v4("127.0.0.1", ec);
VERIFY( !ec );
a4 = ip::make_address_v4(std::string{"256.0.0.1"}, ec);
VERIFY( ec == std::errc::invalid_argument );
ip::make_address_v4(std::string{"127.0.0.1"}, ec);
VERIFY( !ec );
a4 = ip::make_address_v4(std::experimental::string_view{""}, ec);
VERIFY( ec == std::errc::invalid_argument );
}
int
main()
{
test01();
test02();
test03();
}
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/internet>
#include <testsuite_hooks.h>
using std::experimental::net::ip::address_v4;
void
test01()
{
bool test __attribute__((unused)) = false;
address_v4 a;
VERIFY( a.is_unspecified() );
a = address_v4::any();
VERIFY( a.is_unspecified() );
a = address_v4::loopback();
VERIFY( !a.is_unspecified() );
a = address_v4::broadcast();
VERIFY( !a.is_unspecified() );
}
void
test02()
{
bool test __attribute__((unused)) = false;
auto a = address_v4::loopback();
VERIFY( a.is_loopback() );
a = address_v4{0x7F000001};
VERIFY( a.is_loopback() );
a = address_v4{0x7F010203};
VERIFY( a.is_loopback() );
a = address_v4{0x7FFFFFFF};
VERIFY( a.is_loopback() );
a = address_v4::any();
VERIFY( !a.is_loopback() );
a = address_v4::broadcast();
VERIFY( !a.is_loopback() );
}
void
test03()
{
bool test __attribute__((unused)) = false;
auto a = address_v4{0xE0000001};
VERIFY( a.is_multicast() );
a = address_v4{0xE0010203};
VERIFY( a.is_multicast() );
a = address_v4{0xE0FFFFFF};
VERIFY( a.is_multicast() );
a = address_v4{0xF0000000};
VERIFY( !a.is_multicast() );
a = address_v4{0xDFFFFFFF};
VERIFY( !a.is_multicast() );
}
void
test04()
{
bool test __attribute__((unused)) = false;
VERIFY( address_v4::any().to_string() == "0.0.0.0" );
VERIFY( address_v4::loopback().to_string() == "127.0.0.1" );
VERIFY( address_v4::broadcast().to_string() == "255.255.255.255" );
}
void
test05()
{
bool test __attribute__((unused)) = false;
std::ostringstream ss;
ss << address_v4::any() << ' ' << address_v4::loopback() << ' '
<< address_v4::broadcast();
VERIFY( ss.str() == "0.0.0.0 127.0.0.1 255.255.255.255" );
}
int
main()
{
test01();
test02();
test03();
test04();
test05();
}
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/internet>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = false;
using resolver = std::experimental::net::ip::resolver_base;
resolver::flags f = resolver::passive;
VERIFY( (f & resolver::numeric_host) == 0);
f &= resolver::numeric_host;
VERIFY( f == 0 );
VERIFY( (f | resolver::numeric_host) == resolver::numeric_host);
f |= resolver::numeric_host;
VERIFY( f == resolver::numeric_host );
VERIFY( (f ^ resolver::numeric_host) == 0 );
f ^= resolver::numeric_host;
VERIFY( f == 0 );
f = ~resolver::numeric_host;
VERIFY( (f & resolver::numeric_host) == 0);
VERIFY( (f | resolver::numeric_host) == ~resolver::flags{} );
(void) resolver::passive;
(void) resolver::canonical_name;
(void) resolver::numeric_host;
(void) resolver::numeric_service;
(void) resolver::v4_mapped;
(void) resolver::all_matching;
(void) resolver::address_configured;
}
int
main()
{
test01();
}
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/internet>
#include <testsuite_hooks.h>
using namespace std::experimental::net;
void
test01()
{
bool test __attribute__((unused)) = false;
std::error_code ec;
io_context ctx;
ip::tcp::resolver resolv(ctx);
auto addrs = resolv.resolve("localhost", "http", ec);
VERIFY( !ec );
VERIFY( addrs.size() > 0 );
VERIFY( addrs.begin() != addrs.end() );
VERIFY( ! addrs.empty() );
auto addrs2 = resolv.resolve("localhost", "http");
VERIFY( addrs == addrs2 );
}
void
test02()
{
bool test __attribute__((unused)) = false;
std::error_code ec;
io_context ctx;
ip::tcp::resolver resolv(ctx);
auto flags = ip::resolver_base::numeric_host | ip::tcp::resolver::numeric_service;
auto addrs = resolv.resolve("127.0.0.1", "42", flags, ec);
VERIFY( !ec );
VERIFY( addrs.size() > 0 );
VERIFY( addrs.begin() != addrs.end() );
auto addrs2 = resolv.resolve("127.0.0.1", "42", flags);
VERIFY( addrs == addrs2 );
addrs = resolv.resolve("localhost", "42", flags, ec);
VERIFY( ec );
VERIFY( addrs.empty() );
addrs = resolv.resolve("127.0.0.1", "nameserver", flags, ec);
VERIFY( ec );
VERIFY( addrs.empty() );
#if __cpp_exceptions
bool caught = false;
try {
resolv.resolve("localhost", "http", flags);
} catch (const std::system_error& e) {
caught = true;
VERIFY( e.code() == ec );
}
VERIFY( caught );
#endif
}
void
test03()
{
bool test __attribute__((unused)) = false;
std::error_code ec;
io_context ctx;
ip::tcp::resolver resolv(ctx);
auto addrs = resolv.resolve("test.invalid", "http", ec);
VERIFY( ec );
VERIFY( addrs.size() == 0 );
VERIFY( addrs.begin() == addrs.end() );
VERIFY( addrs.empty() );
#if __cpp_exceptions
bool caught = false;
try {
resolv.resolve("test.invalid", "http");
} catch (const std::system_error& e) {
caught = true;
VERIFY( e.code() == ec );
}
VERIFY( caught );
#endif
}
int
main()
{
test01();
test02();
test03();
}
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/internet>
#include <testsuite_hooks.h>
using namespace std::experimental::net;
void
test01()
{
bool test __attribute__((unused)) = false;
std::error_code ec;
io_context ctx;
ip::tcp::resolver resolv(ctx);
ip::tcp::endpoint home{ip::address_v4::loopback(), 80};
auto addrs = resolv.resolve(home, ec);
VERIFY( !ec );
VERIFY( addrs.size() == 1 );
VERIFY( addrs.begin() != addrs.end() );
VERIFY( ! addrs.empty() );
auto addrs2 = resolv.resolve(home);
VERIFY( addrs == addrs2 );
}
int
main()
{
test01();
}
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/timer>
#include <testsuite_hooks.h>
using std::experimental::net::system_timer;
using std::experimental::net::io_context;
void
test01()
{
bool test __attribute__((unused)) = false;
io_context ctx1, ctx2;
system_timer timer1(ctx1);
VERIFY( timer1.get_executor() == ctx1.get_executor() );
VERIFY( timer1.expiry() == system_timer::time_point() );
system_timer timer2(ctx2);
VERIFY( timer2.get_executor() == ctx2.get_executor() );
VERIFY( timer2.get_executor() != timer1.get_executor() );
VERIFY( timer2.expiry() == system_timer::time_point() );
system_timer timer3(std::move(timer1));
VERIFY( timer3.get_executor() == ctx1.get_executor() );
VERIFY( timer3.expiry() == system_timer::time_point() );
VERIFY( timer1.expiry() == system_timer::time_point() );
system_timer timer4(std::move(timer2));
VERIFY( timer4.get_executor() == ctx2.get_executor() );
VERIFY( timer4.expiry() == system_timer::time_point() );
VERIFY( timer2.expiry() == system_timer::time_point() );
}
void
test02()
{
bool test __attribute__((unused)) = false;
io_context ctx1, ctx2;
auto t1 = system_timer::clock_type::now();
auto t2 = t1 + system_timer::duration(10);
system_timer timer1(ctx1, t1);
VERIFY( timer1.get_executor() == ctx1.get_executor() );
VERIFY( timer1.expiry() == t1 );
system_timer timer2(ctx2, t2);
VERIFY( timer2.get_executor() == ctx2.get_executor() );
VERIFY( timer2.get_executor() != timer1.get_executor() );
VERIFY( timer2.expiry() == t2 );
system_timer timer3(std::move(timer1));
VERIFY( timer3.get_executor() == ctx1.get_executor() );
VERIFY( timer3.expiry() == t1 );
VERIFY( timer1.expiry() == system_timer::time_point() );
system_timer timer4(std::move(timer2));
VERIFY( timer4.get_executor() == ctx2.get_executor() );
VERIFY( timer4.expiry() == t2 );
VERIFY( timer2.expiry() == system_timer::time_point() );
}
void
test03()
{
bool test __attribute__((unused)) = false;
io_context ctx1, ctx2;
auto now = system_timer::clock_type::now();
auto d1 = system_timer::duration(10);
auto d2 = system_timer::duration(100);
system_timer timer1(ctx1, d1);
VERIFY( timer1.get_executor() == ctx1.get_executor() );
VERIFY( timer1.expiry() > now );
system_timer timer2(ctx2, d2);
VERIFY( timer2.get_executor() == ctx2.get_executor() );
VERIFY( timer2.get_executor() != timer1.get_executor() );
VERIFY( timer2.expiry() > now );
VERIFY( timer2.expiry() != timer1.expiry() );
system_timer timer3(std::move(timer1));
VERIFY( timer3.get_executor() == ctx1.get_executor() );
VERIFY( timer3.expiry() > now );
VERIFY( timer1.expiry() == system_timer::time_point() );
system_timer timer4(std::move(timer2));
VERIFY( timer4.get_executor() == ctx2.get_executor() );
VERIFY( timer4.expiry() > now );
VERIFY( timer2.expiry() == system_timer::time_point() );
}
int
main()
{
test01();
test02();
test03();
}
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/timer>
#include <testsuite_hooks.h>
using std::experimental::net::system_timer;
using std::experimental::net::io_context;
void
test01()
{
bool test __attribute__((unused)) = false;
std::error_code ec;
io_context ctx;
{
system_timer timer(ctx, system_timer::duration(3600));
timer.async_wait([&ec](std::error_code e) { ec = e; });
}
auto n = ctx.run();
__builtin_printf("ran %lu\n", n);
VERIFY( n == 1 );
VERIFY( ec == std::errc::operation_canceled );
}
int
main()
{
test01();
}
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++14" }
#include <experimental/timer>
#include <testsuite_hooks.h>
using std::experimental::net::system_timer;
using std::experimental::net::io_context;
using std::error_code;
void
test01()
{
bool test __attribute__((unused)) = false;
io_context ctx;
error_code ec;
bool complete = false;
auto then = system_timer::clock_type::now() + system_timer::duration(100);
system_timer timer(ctx, then);
VERIFY( timer.cancel_one() == 0 );
VERIFY( timer.cancel() == 0 );
timer.async_wait([&](error_code e) { ec = e; complete = true; });
VERIFY( timer.cancel_one() == 1 );
VERIFY( !complete );
VERIFY( timer.cancel_one() == 0 );
VERIFY( timer.cancel() == 0 );
VERIFY( ctx.run() == 1 );
VERIFY( ctx.stopped() );
VERIFY( complete );
VERIFY( ec == std::errc::operation_canceled );
}
void
test02()
{
bool test __attribute__((unused)) = false;
io_context ctx;
error_code ec1, ec2;
const auto now = system_timer::clock_type::now();
const auto t1 = now + std::chrono::seconds(100);
const auto t2 = t1 + std::chrono::seconds(100);
system_timer timer(ctx, t1);
VERIFY( timer.expiry() == t1 );
VERIFY( timer.expires_at(t2) == 0 );
VERIFY( timer.expiry() == t2 );
timer.async_wait([&ec1](error_code e) { ec1 = e; });
timer.async_wait([&ec2](error_code e) { ec2 = e; });
auto n = timer.expires_at(t1);
VERIFY( n == 2 );
VERIFY( timer.expiry() == t1 );
VERIFY( ctx.run_one() == 1 );
VERIFY( ! ctx.stopped() );
VERIFY( ctx.run_one() == 1 );
VERIFY( ctx.stopped() );
VERIFY( ec1 == std::errc::operation_canceled );
VERIFY( ec2 == std::errc::operation_canceled );
VERIFY( timer.expires_after(std::chrono::seconds(50)) == 0 );
VERIFY( timer.expiry() < t1 );
ec1.clear();
ec2.clear();
ctx.restart();
timer.async_wait([&ec1](error_code e) { ec1 = e; });
timer.async_wait([&ec2](error_code e) { ec2 = e; });
VERIFY( timer.expires_after(std::chrono::seconds(10)) == 2 );
VERIFY( timer.expiry() < t1 );
ctx.run();
VERIFY( ec1 == std::errc::operation_canceled );
VERIFY( ec2 == std::errc::operation_canceled );
}
int
main()
{
test01();
test02();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment