annotate libstdc++-v3/testsuite/experimental/net/socket/basic_socket.cc @ 19:2b5abeee2509 default tip

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
1 // Copyright (C) 2020 Free Software Foundation, Inc.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
2 //
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
3 // This file is part of the GNU ISO C++ Library. This library is free
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
4 // software; you can redistribute it and/or modify it under the
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
5 // terms of the GNU General Public License as published by the
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
6 // Free Software Foundation; either version 3, or (at your option)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
7 // any later version.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
8
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
9 // This library is distributed in the hope that it will be useful,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
12 // GNU General Public License for more details.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
13
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
14 // You should have received a copy of the GNU General Public License along
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
15 // with this library; see the file COPYING3. If not see
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
16 // <http://www.gnu.org/licenses/>.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
17
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
18 // { dg-do compile { target c++14 } }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
19
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
20 #include <experimental/socket>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
21
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
22 namespace net = std::experimental::net;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
23 using namespace std;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
24
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
25 namespace test
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
26 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
27 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
28
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
29 void
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
30 test01(net::io_context& io)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
31 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
32 struct proto
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
33 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
34 struct endpoint
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
35 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
36 using protocol_type = proto;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
37 protocol_type protocol() const { return {}; }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
38
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
39 void* data() { return nullptr; }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
40 const void* data() const { return nullptr; }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
41 std::size_t size() const { return 0; }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
42 void resize(std::size_t) { }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
43 std::size_t capacity() const { return 0; }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
44 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
45
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
46 int family() const { return 0; }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
47 int type() const { return 0; }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
48 int protocol() const { return 0; }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
49 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
50
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
51 static_assert( ! is_default_constructible<net::basic_socket<proto>>::value,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
52 "no default ctor" );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
53 static_assert( ! is_copy_constructible<net::basic_socket<proto>>::value,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
54 "copy ctor is deleted" );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
55 static_assert( ! is_move_constructible<net::basic_socket<proto>>::value,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
56 "move ctor is protected" );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
57 static_assert( ! is_move_assignable<net::basic_socket<proto>>::value,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
58 "move assignment op is protected" );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
59
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
60 struct socket : net::basic_socket<proto>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
61 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
62 explicit
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
63 socket(net::io_context& io)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
64 : basic_socket(io) { }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
65
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
66 socket(net::io_context& io, const proto& p)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
67 : basic_socket(io, p) { }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
68
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
69 socket(net::io_context& io, const proto::endpoint& e)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
70 : basic_socket(io, e) { }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
71
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
72 socket(net::io_context& io, const proto& p, int n)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
73 : basic_socket(io, p, n) { }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
74 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
75
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
76 static_assert( ! is_copy_constructible<socket>::value, "deleted" );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
77 static_assert( is_move_constructible<socket>::value, "" );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
78 static_assert( is_move_assignable<socket>::value, "" );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
79
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
80 error_code ec;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
81 proto p;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
82 proto::endpoint e;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
83
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
84 socket s(io);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
85 s = socket(io, p);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
86 s = socket(io, e);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
87 s = socket(io, p, s.release());
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
88
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
89 static_assert( is_same<decltype(s.get_executor()),
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
90 net::io_context::executor_type>::value, "" );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
91 static_assert( noexcept(s.get_executor()), "" );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
92 static_assert( is_same<decltype(s.native_handle()),
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
93 socket::native_handle_type>::value, "" );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
94 static_assert( noexcept(s.native_handle()), "GNU extension" );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
95
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
96 s.open();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
97 s.open(p);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
98 s.open(p, ec);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
99
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
100 s.assign(p, s.release());
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
101 s.assign(p, s.release(ec), ec);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
102
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
103 static_assert( is_same<decltype(const_cast<const socket&>(s).is_open()),
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
104 bool>::value, "" );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
105 static_assert( noexcept(const_cast<const socket&>(s).is_open()), "" );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
106
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
107 s.close();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
108 s.close(ec);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
109
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
110 s.cancel();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
111 s.cancel(ec);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
112
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
113 s.bind(e);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
114 s.bind(e, ec);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
115
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
116 s.shutdown(net::socket_base::shutdown_both);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
117 s.shutdown(net::socket_base::shutdown_both, ec);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
118
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
119 e = s.local_endpoint();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
120 e = s.local_endpoint(ec);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
121 e = s.remote_endpoint();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
122 e = s.remote_endpoint(ec);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
123
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
124 s.connect(e);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
125 s.connect(e, ec);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
126
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
127 s.wait(net::socket_base::wait_read);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
128 s.wait(net::socket_base::wait_read, ec);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
129 }