]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/net/socket/basic_socket.cc
1 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do compile { target c++14 } }
20 #include <experimental/socket>
22 namespace net
= std::experimental::net
;
26 test01(net::io_context
& io
)
32 using protocol_type
= proto
;
33 protocol_type
protocol() const { return {}; }
35 void* data() { return nullptr; }
36 const void* data() const { return nullptr; }
37 std::size_t size() const { return 0; }
38 void resize(std::size_t) { }
39 std::size_t capacity() const { return 0; }
42 int family() const { return 0; }
43 int type() const { return 0; }
44 int protocol() const { return 0; }
47 static_assert( ! is_default_constructible
<net::basic_socket
<proto
>>::value
,
49 static_assert( ! is_copy_constructible
<net::basic_socket
<proto
>>::value
,
50 "copy ctor is deleted" );
51 static_assert( ! is_move_constructible
<net::basic_socket
<proto
>>::value
,
52 "move ctor is protected" );
53 static_assert( ! is_move_assignable
<net::basic_socket
<proto
>>::value
,
54 "move assignment op is protected" );
56 struct socket
: net::basic_socket
<proto
>
59 socket(net::io_context
& io
)
60 : basic_socket(io
) { }
62 socket(net::io_context
& io
, const proto
& p
)
63 : basic_socket(io
, p
) { }
65 socket(net::io_context
& io
, const proto::endpoint
& e
)
66 : basic_socket(io
, e
) { }
68 socket(net::io_context
& io
, const proto
& p
, int n
)
69 : basic_socket(io
, p
, n
) { }
72 static_assert( ! is_copy_constructible
<socket
>::value
, "deleted" );
73 static_assert( is_move_constructible
<socket
>::value
, "" );
74 static_assert( is_move_assignable
<socket
>::value
, "" );
83 s
= socket(io
, p
, s
.release());
85 static_assert( is_same
<decltype(s
.get_executor()),
86 net::io_context::executor_type
>::value
, "" );
87 static_assert( noexcept(s
.get_executor()), "" );
88 static_assert( is_same
<decltype(s
.native_handle()),
89 socket::native_handle_type
>::value
, "" );
90 static_assert( noexcept(s
.native_handle()), "GNU extension" );
96 s
.assign(p
, s
.release());
97 s
.assign(p
, s
.release(ec
), ec
);
99 static_assert( is_same
<decltype(const_cast<const socket
&>(s
).is_open()),
101 static_assert( noexcept(const_cast<const socket
&>(s
).is_open()), "" );
113 s
.shutdown(net::socket_base::shutdown_both
);
114 s
.shutdown(net::socket_base::shutdown_both
, ec
);
117 e
= s
.local_endpoint();
118 e
= s
.local_endpoint(ec
);
119 e
= s
.remote_endpoint();
120 e
= s
.remote_endpoint(ec
);
125 s
.wait(net::socket_base::wait_read
);
126 s
.wait(net::socket_base::wait_read
, ec
);