Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-17 08:39:19

0001 //
0002 // Copyright (c) 2024 Klemens Morgenstern (klemens.morgenstern@gmx.net)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_COBALT_IO_PIPE_HPP
0009 #define BOOST_COBALT_IO_PIPE_HPP
0010 
0011 #include <boost/cobalt/io/detail/config.hpp>
0012 #include <boost/cobalt/config.hpp>
0013 #include <boost/cobalt/io/buffer.hpp>
0014 #include <boost/cobalt/io/ops.hpp>
0015 #include <boost/cobalt/io/stream.hpp>
0016 #include <boost/cobalt/op.hpp>
0017 
0018 #include <boost/asio/basic_readable_pipe.hpp>
0019 #include <boost/asio/basic_writable_pipe.hpp>
0020 
0021 #include <boost/system/result.hpp>
0022 
0023 namespace boost::cobalt::io
0024 {
0025 
0026 
0027 BOOST_COBALT_IO_DECL
0028 system::result<std::pair<struct readable_pipe, struct writable_pipe>> pipe(
0029     const executor & executor = this_thread::get_executor()
0030     );
0031 
0032 
0033 struct BOOST_SYMBOL_VISIBLE readable_pipe final : read_stream
0034 {
0035   using native_handle_type = asio::basic_readable_pipe<executor>::native_handle_type;
0036 
0037   BOOST_COBALT_IO_DECL readable_pipe(const cobalt::executor & executor = this_thread::get_executor());
0038   BOOST_COBALT_IO_DECL readable_pipe(native_handle_type native_file, const cobalt::executor & executor = this_thread::get_executor());
0039   BOOST_COBALT_IO_DECL readable_pipe(readable_pipe && sf) noexcept;
0040 
0041   BOOST_COBALT_IO_DECL system::result<void> assign(native_handle_type native_file);
0042   BOOST_COBALT_IO_DECL system::result<void> cancel();
0043 
0044   BOOST_COBALT_IO_DECL executor get_executor();
0045   BOOST_COBALT_IO_DECL bool is_open() const;
0046 
0047   BOOST_COBALT_IO_DECL system::result<void> close();
0048 
0049   BOOST_COBALT_IO_DECL native_handle_type native_handle();
0050   BOOST_COBALT_IO_DECL system::result<native_handle_type> release();
0051 
0052   [[nodiscard]] read_op read_some(mutable_buffer_sequence buffer)
0053   {
0054     return {buffer, this, initiate_read_some_};
0055   }
0056 
0057  private:
0058 
0059   BOOST_COBALT_IO_DECL static void initiate_read_some_(void *, mutable_buffer_sequence, boost::cobalt::completion_handler<system::error_code, std::size_t>);
0060 
0061   BOOST_COBALT_IO_DECL
0062   friend system::result<std::pair<struct readable_pipe, struct writable_pipe>> pipe(const cobalt::executor & executor);
0063   asio::basic_readable_pipe<executor> implementation_;
0064 
0065 };
0066 
0067 
0068 struct BOOST_SYMBOL_VISIBLE writable_pipe final : write_stream
0069 {
0070   using native_handle_type = asio::basic_writable_pipe<executor>::native_handle_type;
0071 
0072   BOOST_COBALT_IO_DECL writable_pipe(const cobalt::executor & executor = this_thread::get_executor());
0073   BOOST_COBALT_IO_DECL writable_pipe(native_handle_type native_file, const cobalt::executor & executor = this_thread::get_executor());
0074   BOOST_COBALT_IO_DECL writable_pipe(writable_pipe && sf) noexcept;
0075 
0076   BOOST_COBALT_IO_DECL system::result<void> assign(native_handle_type native_file);
0077   BOOST_COBALT_IO_DECL system::result<void> cancel();
0078 
0079   BOOST_COBALT_IO_DECL executor get_executor();
0080   BOOST_COBALT_IO_DECL bool is_open() const;
0081 
0082   [[nodiscard]] write_op write_some(const_buffer_sequence buffer)
0083   {
0084     return {buffer, this, initiate_write_some_};
0085   }
0086 
0087   BOOST_COBALT_IO_DECL system::result<void> close();
0088 
0089   BOOST_COBALT_IO_DECL native_handle_type native_handle();
0090 
0091   BOOST_COBALT_IO_DECL system::result<native_handle_type> release();
0092 
0093  private:
0094   BOOST_COBALT_IO_DECL static void initiate_write_some_(void *, const_buffer_sequence, boost::cobalt::completion_handler<system::error_code, std::size_t>);
0095 
0096   BOOST_COBALT_IO_DECL
0097   friend system::result<std::pair<struct readable_pipe, struct  writable_pipe>> pipe(const cobalt::executor & executor);
0098   asio::basic_writable_pipe<executor> implementation_;
0099 };
0100 
0101 }
0102 
0103 namespace boost::process
0104 {
0105 template<typename T>
0106 struct is_readable_pipe;
0107 
0108 template<>
0109 struct is_readable_pipe<boost::cobalt::io::readable_pipe> : std::true_type
0110 {
0111 };
0112 
0113 
0114 template<typename T>
0115 struct is_writable_pipe;
0116 
0117 template<>
0118 struct is_writable_pipe<boost::cobalt::io::writable_pipe> : std::true_type
0119 {
0120 };
0121 }
0122 
0123 #endif //BOOST_COBALT_IO_PIPE_HPP