1 // Networking implementation details -*- C++ -*-
3 // Copyright (C) 2015-2020 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file experimental/bits/net.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{experimental/net}
30 #ifndef _GLIBCXX_EXPERIMENTAL_NET_H
31 #define _GLIBCXX_EXPERIMENTAL_NET_H 1
33 #pragma GCC system_header
35 #if __cplusplus >= 201402L
37 #include <type_traits>
38 #include <system_error>
39 #include <experimental/netfwd>
41 namespace std
_GLIBCXX_VISIBILITY(default)
43 _GLIBCXX_BEGIN_NAMESPACE_VERSION
44 namespace experimental
51 /** @addtogroup networking-ts
55 template<typename _CompletionToken
, typename _Signature
, typename
>
58 /// @cond undocumented
60 // A type denoted by DEDUCED in the TS.
61 template<typename _CompletionToken
, typename _Signature
>
62 using __deduced_t
= typename
63 async_result
<decay_t
<_CompletionToken
>, _Signature
, void>::return_type
;
65 // Trait to check for construction from const/non-const lvalue/rvalue.
66 template<typename _Tp
>
67 using __is_value_constructible
= typename __and_
<
68 is_copy_constructible
<_Tp
>, is_move_constructible
<_Tp
>,
69 is_constructible
<_Tp
, _Tp
&>, is_constructible
<_Tp
, const _Tp
&&>
72 struct __throw_on_error
75 __throw_on_error(const char* __msg
) : _M_msg(__msg
) { }
77 ~__throw_on_error() noexcept(false)
80 _GLIBCXX_THROW_OR_ABORT(system_error(_M_ec
, _M_msg
));
83 __throw_on_error(const __throw_on_error
&) = delete;
84 __throw_on_error
& operator=(const __throw_on_error
&) = delete;
86 operator error_code
&() noexcept
{ return _M_ec
; }
94 // Base class for types meeting IntegerSocketOption requirements.
95 template<typename _Tp
>
98 __sockopt_base() = default;
100 explicit __sockopt_base(int __val
) : _M_value(__val
) { }
102 int value() const noexcept
{ return _M_value
; }
104 template<typename _Protocol
>
106 data(const _Protocol
&) noexcept
107 { return std::addressof(_M_value
); }
109 template<typename _Protocol
>
111 data(const _Protocol
&) const noexcept
112 { return std::addressof(_M_value
); }
114 template<typename _Protocol
>
116 size(const _Protocol
&) const noexcept
117 { return sizeof(_M_value
); }
119 template<typename _Protocol
>
121 resize(const _Protocol
&, size_t __s
)
123 if (__s
!= sizeof(_M_value
))
124 __throw_length_error("invalid value for socket option resize");
131 // Base class for types meeting BooleanSocketOption requirements.
133 struct __sockopt_base
<bool> : __sockopt_base
<int>
135 __sockopt_base() = default;
137 explicit __sockopt_base(bool __val
) : __sockopt_base
<int>(__val
) { }
139 bool value() const noexcept
{ return __sockopt_base
<int>::_M_value
; }
140 explicit operator bool() const noexcept
{ return value(); }
141 bool operator!() const noexcept
{ return !value(); }
144 template<typename _Derived
, typename _Tp
= int>
145 struct __sockopt_crtp
: __sockopt_base
<_Tp
>
147 using __sockopt_base
<_Tp
>::__sockopt_base
;
150 operator=(_Tp __value
)
152 __sockopt_base
<_Tp
>::_M_value
= __value
;
153 return static_cast<_Derived
&>(*this);
156 template<typename _Protocol
>
158 level(const _Protocol
&) const noexcept
159 { return _Derived::_S_level
; }
161 template<typename _Protocol
>
163 name(const _Protocol
&) const noexcept
164 { return _Derived::_S_name
; }
171 } // namespace experimental
172 _GLIBCXX_END_NAMESPACE_VERSION
177 #endif // _GLIBCXX_EXPERIMENTAL_NET_H