100.00% Lines (2/2) 100.00% Functions (2/2)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2026 Steve Gerbino 2   // Copyright (c) 2026 Steve Gerbino
3   // 3   //
4   // Distributed under the Boost Software License, Version 1.0. (See accompanying 4   // Distributed under the Boost Software License, Version 1.0. (See accompanying
5   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6   // 6   //
7   // Official repository: https://github.com/cppalliance/corosio 7   // Official repository: https://github.com/cppalliance/corosio
8   // 8   //
9   9  
10   #ifndef BOOST_COROSIO_DETAIL_UDP_SERVICE_HPP 10   #ifndef BOOST_COROSIO_DETAIL_UDP_SERVICE_HPP
11   #define BOOST_COROSIO_DETAIL_UDP_SERVICE_HPP 11   #define BOOST_COROSIO_DETAIL_UDP_SERVICE_HPP
12   12  
13   #include <boost/corosio/detail/config.hpp> 13   #include <boost/corosio/detail/config.hpp>
14   #include <boost/corosio/udp_socket.hpp> 14   #include <boost/corosio/udp_socket.hpp>
15   #include <boost/corosio/endpoint.hpp> 15   #include <boost/corosio/endpoint.hpp>
16   #include <boost/capy/ex/execution_context.hpp> 16   #include <boost/capy/ex/execution_context.hpp>
17   #include <system_error> 17   #include <system_error>
18   18  
19   namespace boost::corosio::detail { 19   namespace boost::corosio::detail {
20   20  
21   /** Abstract UDP service base class. 21   /** Abstract UDP service base class.
22   22  
23   Concrete implementations (epoll_udp_service, 23   Concrete implementations (epoll_udp_service,
24   select_udp_service, etc.) inherit from this class and 24   select_udp_service, etc.) inherit from this class and
25   provide platform-specific datagram socket operations. The 25   provide platform-specific datagram socket operations. The
26   context constructor installs whichever backend via 26   context constructor installs whichever backend via
27   `make_service`, and `udp_socket.cpp` retrieves it via 27   `make_service`, and `udp_socket.cpp` retrieves it via
28   `use_service<udp_service>()`. 28   `use_service<udp_service>()`.
29   */ 29   */
30   class BOOST_COROSIO_DECL udp_service 30   class BOOST_COROSIO_DECL udp_service
31   : public capy::execution_context::service 31   : public capy::execution_context::service
32   , public io_object::io_service 32   , public io_object::io_service
33   { 33   {
34   public: 34   public:
35   /// Identifies this service for `execution_context` lookup. 35   /// Identifies this service for `execution_context` lookup.
36   using key_type = udp_service; 36   using key_type = udp_service;
37   37  
38   /** Open a datagram socket. 38   /** Open a datagram socket.
39   39  
40   Creates a socket and associates it with the platform reactor. 40   Creates a socket and associates it with the platform reactor.
41   41  
42   @param impl The socket implementation to open. 42   @param impl The socket implementation to open.
43   @param family Address family (e.g. `AF_INET`, `AF_INET6`). 43   @param family Address family (e.g. `AF_INET`, `AF_INET6`).
44   @param type Socket type (`SOCK_DGRAM`). 44   @param type Socket type (`SOCK_DGRAM`).
45   @param protocol Protocol number (`IPPROTO_UDP`). 45   @param protocol Protocol number (`IPPROTO_UDP`).
46   @return Error code on failure, empty on success. 46   @return Error code on failure, empty on success.
47   */ 47   */
48   virtual std::error_code open_datagram_socket( 48   virtual std::error_code open_datagram_socket(
49   udp_socket::implementation& impl, 49   udp_socket::implementation& impl,
50   int family, 50   int family,
51   int type, 51   int type,
52   int protocol) = 0; 52   int protocol) = 0;
53   53  
54   /** Assign an existing native socket handle to a socket. 54   /** Assign an existing native socket handle to a socket.
55   55  
56   Adopts a pre-created socket handle. On success the impl 56   Adopts a pre-created socket handle. On success the impl
57   takes ownership and will close the handle. On failure the 57   takes ownership and will close the handle. On failure the
58   caller retains ownership and must close it. If the impl is 58   caller retains ownership and must close it. If the impl is
59   already open, its pending operations are cancelled and the 59   already open, its pending operations are cancelled and the
60   held socket is closed before the new one is adopted. 60   held socket is closed before the new one is adopted.
61   61  
62   @param impl The socket implementation to assign to. 62   @param impl The socket implementation to assign to.
63   @param fd The native socket handle to adopt. 63   @param fd The native socket handle to adopt.
64   @return Error code on failure, empty on success. 64   @return Error code on failure, empty on success.
65   */ 65   */
66   virtual std::error_code assign_socket( 66   virtual std::error_code assign_socket(
67   udp_socket::implementation& impl, 67   udp_socket::implementation& impl,
68   native_handle_type fd) = 0; 68   native_handle_type fd) = 0;
69   69  
70   /** Bind a datagram socket to a local endpoint. 70   /** Bind a datagram socket to a local endpoint.
71   71  
72   @param impl The socket implementation to bind. 72   @param impl The socket implementation to bind.
73   @param ep The local endpoint to bind to. 73   @param ep The local endpoint to bind to.
74   @return Error code on failure, empty on success. 74   @return Error code on failure, empty on success.
75   */ 75   */
76   virtual std::error_code 76   virtual std::error_code
77   bind_datagram(udp_socket::implementation& impl, endpoint ep) = 0; 77   bind_datagram(udp_socket::implementation& impl, endpoint ep) = 0;
78   78  
79   protected: 79   protected:
80   /// Construct the UDP service. 80   /// Construct the UDP service.
HITCBC 81   1533 udp_service() = default; 81   1603 udp_service() = default;
82   82  
83   /// Destroy the UDP service. 83   /// Destroy the UDP service.
HITCBC 84   1533 ~udp_service() override = default; 84   1603 ~udp_service() override = default;
85   }; 85   };
86   86  
87   } // namespace boost::corosio::detail 87   } // namespace boost::corosio::detail
88   88  
89   #endif // BOOST_COROSIO_DETAIL_UDP_SERVICE_HPP 89   #endif // BOOST_COROSIO_DETAIL_UDP_SERVICE_HPP