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_IODATAGRAM_SOCKET_HPP
0009 #define BOOST_COBALT_IODATAGRAM_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 
0015 #include <boost/asio/generic/datagram_protocol.hpp>
0016 #include <boost/asio/basic_datagram_socket.hpp>
0017 
0018 namespace boost::cobalt::io
0019 {
0020 
0021 struct BOOST_SYMBOL_VISIBLE datagram_socket final : socket
0022 {
0023   BOOST_COBALT_IO_DECL datagram_socket(const cobalt::executor & executor = this_thread::get_executor());
0024   BOOST_COBALT_IO_DECL datagram_socket(datagram_socket && lhs);
0025   BOOST_COBALT_IO_DECL datagram_socket(native_handle_type h, protocol_type protocol = protocol_type(),
0026                   const cobalt::executor & executor = this_thread::get_executor());
0027   BOOST_COBALT_IO_DECL datagram_socket(endpoint ep,
0028                   const cobalt::executor & executor = this_thread::get_executor());
0029 
0030   [[nodiscard]]  write_op send(const_buffer_sequence buffer)
0031   {
0032     return {buffer, this, initiate_send_};
0033   }
0034   [[nodiscard]] read_op receive(mutable_buffer_sequence buffer)
0035   {
0036     return {buffer, this, initiate_receive_};
0037   }
0038 
0039  private:
0040   BOOST_COBALT_IO_DECL void adopt_endpoint_(endpoint & ep) override;
0041 
0042   BOOST_COBALT_IO_DECL static void initiate_receive_(void *, mutable_buffer_sequence, boost::cobalt::completion_handler<system::error_code, std::size_t>);
0043   BOOST_COBALT_IO_DECL static void initiate_send_   (void *,   const_buffer_sequence, boost::cobalt::completion_handler<system::error_code, std::size_t>);
0044 
0045   asio::basic_datagram_socket<protocol_type, executor> datagram_socket_;
0046 };
0047 
0048 
0049 inline system::result<std::pair<datagram_socket, datagram_socket>> make_pair(decltype(local_datagram) protocol)
0050 {
0051   std::pair<datagram_socket, datagram_socket> res;
0052   auto c = connect_pair(protocol, res.first, res.second);
0053   if (c)
0054     return res;
0055   else
0056     return c.error();
0057 }
0058 
0059 }
0060 
0061 #endif //BOOST_COBALT_IODATAGRAM_SOCKET_HPP