30 #ifndef _GLIBCXX_EXPERIMENTAL_NET_H
31 #define _GLIBCXX_EXPERIMENTAL_NET_H 1
33 #pragma GCC system_header
35 #if __cplusplus >= 201402L
39 #include <experimental/netfwd>
41 #if __cplusplus > 201703L
45 namespace std _GLIBCXX_VISIBILITY(default)
47 _GLIBCXX_BEGIN_NAMESPACE_VERSION
48 namespace experimental
59 template<
typename _CompletionToken,
typename _Signature,
typename>
65 template<
typename _CompletionToken,
typename _Signature>
66 using __deduced_t =
typename
67 async_result<decay_t<_CompletionToken>, _Signature,
void>::return_type;
70 template<
typename _Tp>
71 using __is_value_constructible =
typename __and_<
72 is_copy_constructible<_Tp>, is_move_constructible<_Tp>,
73 is_constructible<_Tp, _Tp&>, is_constructible<_Tp, const _Tp&&>
76 struct __throw_on_error
79 __throw_on_error(
const char* __msg) : _M_msg(__msg) { }
81 ~__throw_on_error() noexcept(false)
84 _GLIBCXX_THROW_OR_ABORT(system_error(_M_ec, _M_msg));
87 __throw_on_error(
const __throw_on_error&) =
delete;
88 __throw_on_error&
operator=(
const __throw_on_error&) =
delete;
90 operator error_code&() noexcept {
return _M_ec; }
99 template<
typename _Tp>
100 struct __sockopt_base
102 __sockopt_base() =
default;
104 explicit __sockopt_base(
int __val) : _M_value(__val) { }
106 int value() const noexcept {
return _M_value; }
108 template<
typename _Protocol>
110 data(
const _Protocol&) noexcept
113 template<
typename _Protocol>
115 data(
const _Protocol&) const noexcept
118 template<
typename _Protocol>
120 size(
const _Protocol&) const noexcept
121 {
return sizeof(_M_value); }
123 template<
typename _Protocol>
125 resize(
const _Protocol&,
size_t __s)
127 if (__s !=
sizeof(_M_value))
128 __throw_length_error(
"invalid value for socket option resize");
137 struct __sockopt_base<bool> : __sockopt_base<int>
139 __sockopt_base() =
default;
141 explicit __sockopt_base(
bool __val) : __sockopt_base<int>(__val) { }
143 bool value() const noexcept {
return __sockopt_base<int>::_M_value; }
144 explicit operator bool() const noexcept {
return value(); }
145 bool operator!() const noexcept {
return !value(); }
148 template<
typename _Derived,
typename _Tp =
int>
149 struct __sockopt_crtp : __sockopt_base<_Tp>
151 using __sockopt_base<_Tp>::__sockopt_base;
156 __sockopt_base<_Tp>::_M_value = __value;
157 return static_cast<_Derived&
>(*this);
160 template<
typename _Protocol>
162 level(
const _Protocol&) const noexcept
163 {
return _Derived::_S_level; }
165 template<
typename _Protocol>
167 name(
const _Protocol&) const noexcept
168 {
return _Derived::_S_name; }
173 #if __cpp_lib_concepts
174 template<
typename _Tp>
175 concept __protocol_like
176 = copyable<_Tp> && requires {
typename _Tp::endpoint; };
179 template<
typename _Tp>
180 concept __endpoint_base = semiregular<_Tp>
181 && requires {
typename _Tp::protocol_type; }
182 && __protocol_like<typename _Tp::protocol_type>
183 && requires(
const _Tp __a) {
184 { __a.protocol() } -> same_as<typename _Tp::protocol_type>;
188 template<
typename _Tp>
189 concept __endpoint = __endpoint_base<_Tp>
190 && requires (
const _Tp& __a, _Tp& __b,
size_t __s)
192 { __a.data() } -> same_as<const void*>;
193 { __b.data() } -> same_as<void*>;
194 { __b.size() } -> same_as<size_t>;
196 { __a.capacity() } -> same_as<size_t>;
200 template<
typename _Tp>
201 concept __protocol_base = __protocol_like<_Tp>
202 && __endpoint_base<typename _Tp::endpoint>
203 && same_as<typename _Tp::endpoint::protocol_type, _Tp>;
206 template<
typename _Tp>
207 concept __protocol = __protocol_base<_Tp>
208 && __endpoint<typename _Tp::endpoint>
209 && requires (
const _Tp __a) {
210 { __a.family() } -> same_as<int>;
211 { __a.type() } -> same_as<int>;
212 { __a.protocol() } -> same_as<int>;
215 template<
typename _Tp>
216 concept __acceptable_protocol = __protocol<_Tp>
217 && requires {
typename _Tp::socket; }
218 && move_constructible<typename _Tp::socket>
219 && derived_from<typename _Tp::socket, basic_socket<_Tp>>;
221 template<
typename _Tp>
222 concept __inet_protocol = __acceptable_protocol<_Tp>
223 && equality_comparable<_Tp> && requires {
224 { _Tp::v4() } -> same_as<_Tp>;
225 { _Tp::v6() } -> same_as<_Tp>;
226 typename _Tp::resolver;
228 && same_as<typename _Tp::resolver, ip::basic_resolver<_Tp>>;
232 template<
typename _Tp,
typename =
void>
236 template<
typename _Tp>
238 __endpoint_reqs(
const _Tp* __a =
nullptr, _Tp* __b =
nullptr)
240 is_default_constructible<_Tp>, __is_value_constructible<_Tp>,
241 is_same<decltype(__a->protocol()),
typename _Tp::protocol_type>,
242 is_same<decltype(__a->data()),
const void*>,
243 is_same<decltype(__b->data()),
void*>,
244 is_same<decltype(__a->size()),
size_t>,
245 is_same<decltype(__a->capacity()),
size_t>
247 __void_t<
typename _Tp::protocol_type::endpoint,
248 decltype(__b->resize(std::declval<size_t>())) >>;
250 template<
typename _Tp>
251 struct __is_endpoint<_Tp, decltype(__detail::__endpoint_reqs<_Tp>())>
256 template<
typename _Tp,
typename =
void>
260 template<
typename _Tp>
262 __protocol_reqs(
const _Tp* __a =
nullptr)
264 is_copy_constructible<_Tp>, is_copy_assignable<_Tp>,
265 __is_endpoint<typename _Tp::endpoint>,
266 is_same<decltype(__a->family()),
int>,
267 is_same<decltype(__a->type()),
int>,
268 is_same<decltype(__a->protocol()),
int>
271 template<
typename _Tp>
272 struct __is_protocol<_Tp, decltype(__detail::__protocol_reqs<_Tp>())>
277 template<
typename _Tp,
typename =
void>
278 struct __is_acceptable_protocol
281 template<
typename _Tp>
282 struct __is_acceptable_protocol<_Tp, __void_t<typename _Tp::socket>>
283 : __and_<__is_protocol<_Tp>, is_move_constructible<typename _Tp::socket>,
284 is_convertible<typename _Tp::socket*, basic_socket<_Tp>*>>::type
288 template<
typename _Tp,
typename =
void>
289 struct __is_inet_protocol
292 template<
typename _Tp>
294 __inet_proto_reqs(
const _Tp* __a =
nullptr)
296 __is_acceptable_protocol<_Tp>,
297 is_same<typename _Tp::resolver, ip::basic_resolver<_Tp>>,
298 is_same<decltype(_Tp::v4()), _Tp>,
299 is_same<decltype(_Tp::v6()), _Tp>,
300 is_convertible<decltype(*__a == *__a), bool>,
301 is_convertible<decltype(*__a != *__a), bool>
304 template<
typename _Tp>
305 struct __is_inet_protocol<_Tp, decltype(__inet_proto_reqs<_Tp>())>
310 template<
typename _Tp>
311 constexpr
bool __endpoint = __is_endpoint<_Tp>::value;
312 template<
typename _Tp>
313 constexpr
bool __protocol = __is_protocol<_Tp>::value;
314 template<
typename _Tp>
315 constexpr
bool __acceptable_protocol = __is_acceptable_protocol<_Tp>::value;
324 _GLIBCXX_END_NAMESPACE_VERSION
329 #endif // _GLIBCXX_EXPERIMENTAL_NET_H
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
constexpr auto data(_Container &__cont) noexcept(noexcept(__cont.data())) -> decltype(__cont.data())
Return the data pointer of a container.
constexpr _Tp * addressof(_Tp &__r) noexcept
Returns the actual address of the object or function referenced by r, even in the presence of an over...
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
auto_ptr & operator=(auto_ptr &__a)
auto_ptr assignment operator.