]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/example/cpp14/parallel_group/wait_for_one_error.cpp
2 // wait_for_one_error.cpp
3 // ~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #include <boost/asio.hpp>
12 #include <boost/asio/experimental/parallel_group.hpp>
15 #if defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
19 boost::asio::io_context ctx
;
21 boost::asio::posix::stream_descriptor
in(ctx
, ::dup(STDIN_FILENO
));
22 boost::asio::steady_timer
timer(ctx
, std::chrono::seconds(5));
26 boost::asio::experimental::make_parallel_group(
29 return in
.async_read_some(boost::asio::buffer(data
), token
);
33 return timer
.async_wait(token
);
36 boost::asio::experimental::wait_for_one_error(),
38 std::array
<std::size_t, 2> completion_order
,
39 boost::system::error_code ec1
, std::size_t n1
,
40 boost::system::error_code ec2
43 switch (completion_order
[0])
47 std::cout
<< "descriptor finished: " << ec1
<< ", " << n1
<< "\n";
52 std::cout
<< "timer finished: " << ec2
<< "\n";
62 #else // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
64 #endif // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)