File indexing completed on 2026-08-17 08:39:20
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_COBALT_IO_STREAM_SOCKET_HPP
0009 #define BOOST_COBALT_IO_STREAM_SOCKET_HPP
0010
0011 #include <boost/cobalt/io/detail/config.hpp>
0012 #include <boost/cobalt/io/endpoint.hpp>
0013 #include <boost/cobalt/io/socket.hpp>
0014 #include <boost/cobalt/io/stream.hpp>
0015
0016 #include <boost/asio/generic/datagram_protocol.hpp>
0017 #include <boost/asio/basic_stream_socket.hpp>
0018
0019 namespace boost::cobalt::io
0020 {
0021
0022 struct BOOST_SYMBOL_VISIBLE stream_socket final : socket, stream
0023 {
0024
0025 BOOST_COBALT_IO_DECL stream_socket(const cobalt::executor & executor = this_thread::get_executor());
0026 BOOST_COBALT_IO_DECL stream_socket(stream_socket && lhs);
0027 BOOST_COBALT_IO_DECL stream_socket(native_handle_type h, protocol_type protocol = protocol_type(),
0028 const cobalt::executor & executor = this_thread::get_executor());
0029 BOOST_COBALT_IO_DECL stream_socket(endpoint ep,
0030 const cobalt::executor & executor = this_thread::get_executor());
0031
0032 [[nodiscard]] write_op write_some(const_buffer_sequence buffer) override
0033 {
0034 return {buffer, this, initiate_write_some_};
0035 }
0036 [[nodiscard]] read_op read_some(mutable_buffer_sequence buffer) override
0037 {
0038 return {buffer, this, initiate_read_some_};
0039 }
0040
0041 public:
0042 BOOST_COBALT_IO_DECL void adopt_endpoint_(endpoint & ep) override;
0043
0044 BOOST_COBALT_IO_DECL static void initiate_read_some_ (void *, mutable_buffer_sequence, boost::cobalt::completion_handler<system::error_code, std::size_t>);
0045 BOOST_COBALT_IO_DECL static void initiate_write_some_(void *, const_buffer_sequence, boost::cobalt::completion_handler<system::error_code, std::size_t>);
0046
0047 asio::basic_stream_socket<protocol_type, executor> stream_socket_;
0048 friend struct ssl_stream;
0049 };
0050
0051
0052 inline system::result<std::pair<stream_socket, stream_socket>> make_pair(decltype(local_stream) protocol)
0053 {
0054 std::pair<stream_socket, stream_socket> res;
0055 auto c = connect_pair(protocol, res.first, res.second);
0056 if (c)
0057 return res;
0058 else
0059 return c.error();
0060 }
0061
0062 }
0063
0064 #endif