]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/asio/test/posix/stream_descriptor.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / asio / test / posix / stream_descriptor.cpp
CommitLineData
7c673cae
FG
1//
2// stream_descriptor.cpp
3// ~~~~~~~~~~~~~~~~~~~~~
4//
92f5a8d4 5// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7c673cae
FG
6//
7// Distributed under the Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9//
10
11// Disable autolinking for unit tests.
12#if !defined(BOOST_ALL_NO_LIB)
13#define BOOST_ALL_NO_LIB 1
14#endif // !defined(BOOST_ALL_NO_LIB)
15
16// Test that header file is self-contained.
17#include <boost/asio/posix/stream_descriptor.hpp>
18
b32b8144 19#include <boost/asio/io_context.hpp>
7c673cae
FG
20#include "../archetypes/async_result.hpp"
21#include "../unit_test.hpp"
22
23//------------------------------------------------------------------------------
24
25// posix_stream_descriptor_compile test
26// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27// The following test checks that all public member functions on the class
28// posix::stream_descriptor compile and link correctly. Runtime failures are
29// ignored.
30
31namespace posix_stream_descriptor_compile {
32
b32b8144
FG
33void wait_handler(const boost::system::error_code&)
34{
35}
36
7c673cae
FG
37void write_some_handler(const boost::system::error_code&, std::size_t)
38{
39}
40
41void read_some_handler(const boost::system::error_code&, std::size_t)
42{
43}
44
45void test()
46{
47#if defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
48 using namespace boost::asio;
49 namespace posix = boost::asio::posix;
50
51 try
52 {
b32b8144 53 io_context ioc;
92f5a8d4 54 const io_context::executor_type ioc_ex = ioc.get_executor();
7c673cae
FG
55 char mutable_char_buffer[128] = "";
56 const char const_char_buffer[128] = "";
57 posix::descriptor_base::bytes_readable io_control_command;
58 archetypes::lazy_handler lazy;
59 boost::system::error_code ec;
60
61 // basic_stream_descriptor constructors.
62
b32b8144 63 posix::stream_descriptor descriptor1(ioc);
92f5a8d4 64 posix::stream_descriptor descriptor2(ioc_ex);
7c673cae 65 int native_descriptor1 = -1;
92f5a8d4
TL
66 posix::stream_descriptor descriptor3(ioc, native_descriptor1);
67 posix::stream_descriptor descriptor4(ioc_ex, native_descriptor1);
7c673cae
FG
68
69#if defined(BOOST_ASIO_HAS_MOVE)
92f5a8d4 70 posix::stream_descriptor descriptor5(std::move(descriptor2));
7c673cae
FG
71#endif // defined(BOOST_ASIO_HAS_MOVE)
72
73 // basic_stream_descriptor operators.
74
75#if defined(BOOST_ASIO_HAS_MOVE)
b32b8144 76 descriptor1 = posix::stream_descriptor(ioc);
7c673cae
FG
77 descriptor1 = std::move(descriptor2);
78#endif // defined(BOOST_ASIO_HAS_MOVE)
79
80 // basic_io_object functions.
81
b32b8144
FG
82 posix::stream_descriptor::executor_type ex = descriptor1.get_executor();
83 (void)ex;
7c673cae
FG
84
85 // basic_descriptor functions.
86
87 posix::stream_descriptor::lowest_layer_type& lowest_layer
88 = descriptor1.lowest_layer();
89 (void)lowest_layer;
90
92f5a8d4 91 const posix::stream_descriptor& descriptor6 = descriptor1;
7c673cae 92 const posix::stream_descriptor::lowest_layer_type& lowest_layer2
92f5a8d4 93 = descriptor6.lowest_layer();
7c673cae
FG
94 (void)lowest_layer2;
95
96 int native_descriptor2 = -1;
97 descriptor1.assign(native_descriptor2);
98
99 bool is_open = descriptor1.is_open();
100 (void)is_open;
101
102 descriptor1.close();
103 descriptor1.close(ec);
104
b32b8144
FG
105 posix::stream_descriptor::native_handle_type native_descriptor3
106 = descriptor1.native_handle();
7c673cae
FG
107 (void)native_descriptor3;
108
109 posix::stream_descriptor::native_handle_type native_descriptor4
7c673cae 110 = descriptor1.release();
b32b8144 111 (void)native_descriptor4;
7c673cae
FG
112
113 descriptor1.cancel();
114 descriptor1.cancel(ec);
115
116 descriptor1.io_control(io_control_command);
117 descriptor1.io_control(io_control_command, ec);
118
119 bool non_blocking1 = descriptor1.non_blocking();
120 (void)non_blocking1;
121 descriptor1.non_blocking(true);
122 descriptor1.non_blocking(false, ec);
123
124 bool non_blocking2 = descriptor1.native_non_blocking();
125 (void)non_blocking2;
126 descriptor1.native_non_blocking(true);
127 descriptor1.native_non_blocking(false, ec);
128
b32b8144
FG
129 descriptor1.wait(posix::descriptor_base::wait_read);
130 descriptor1.wait(posix::descriptor_base::wait_write, ec);
131
132 descriptor1.async_wait(posix::descriptor_base::wait_read, &wait_handler);
133 int i1 = descriptor1.async_wait(posix::descriptor_base::wait_write, lazy);
134 (void)i1;
135
7c673cae
FG
136 // basic_stream_descriptor functions.
137
138 descriptor1.write_some(buffer(mutable_char_buffer));
139 descriptor1.write_some(buffer(const_char_buffer));
140 descriptor1.write_some(null_buffers());
141 descriptor1.write_some(buffer(mutable_char_buffer), ec);
142 descriptor1.write_some(buffer(const_char_buffer), ec);
143 descriptor1.write_some(null_buffers(), ec);
144
145 descriptor1.async_write_some(buffer(mutable_char_buffer),
146 write_some_handler);
147 descriptor1.async_write_some(buffer(const_char_buffer),
148 write_some_handler);
149 descriptor1.async_write_some(null_buffers(),
150 write_some_handler);
b32b8144 151 int i2 = descriptor1.async_write_some(buffer(mutable_char_buffer), lazy);
7c673cae 152 (void)i2;
b32b8144 153 int i3 = descriptor1.async_write_some(buffer(const_char_buffer), lazy);
7c673cae 154 (void)i3;
b32b8144
FG
155 int i4 = descriptor1.async_write_some(null_buffers(), lazy);
156 (void)i4;
7c673cae
FG
157
158 descriptor1.read_some(buffer(mutable_char_buffer));
159 descriptor1.read_some(buffer(mutable_char_buffer), ec);
160 descriptor1.read_some(null_buffers(), ec);
161
162 descriptor1.async_read_some(buffer(mutable_char_buffer), read_some_handler);
163 descriptor1.async_read_some(null_buffers(), read_some_handler);
b32b8144 164 int i5 = descriptor1.async_read_some(buffer(mutable_char_buffer), lazy);
7c673cae 165 (void)i5;
b32b8144
FG
166 int i6 = descriptor1.async_read_some(null_buffers(), lazy);
167 (void)i6;
7c673cae
FG
168 }
169 catch (std::exception&)
170 {
171 }
172#endif // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
173}
174
175} // namespace posix_stream_descriptor_compile
176
177//------------------------------------------------------------------------------
178
179BOOST_ASIO_TEST_SUITE
180(
181 "posix/stream_descriptor",
182 BOOST_ASIO_TEST_CASE(posix_stream_descriptor_compile::test)
183)