TLA Line data Source code
1 : //
2 : // Copyright (c) 2026 Steve Gerbino
3 : //
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)
6 : //
7 : // Official repository: https://github.com/cppalliance/corosio
8 : //
9 :
10 : #ifndef BOOST_COROSIO_DETAIL_UDP_SERVICE_HPP
11 : #define BOOST_COROSIO_DETAIL_UDP_SERVICE_HPP
12 :
13 : #include <boost/corosio/detail/config.hpp>
14 : #include <boost/corosio/udp_socket.hpp>
15 : #include <boost/corosio/endpoint.hpp>
16 : #include <boost/capy/ex/execution_context.hpp>
17 : #include <system_error>
18 :
19 : namespace boost::corosio::detail {
20 :
21 : /** Abstract UDP service base class.
22 :
23 : Concrete implementations (epoll_udp_service,
24 : select_udp_service, etc.) inherit from this class and
25 : provide platform-specific datagram socket operations. The
26 : context constructor installs whichever backend via
27 : `make_service`, and `udp_socket.cpp` retrieves it via
28 : `use_service<udp_service>()`.
29 : */
30 : class BOOST_COROSIO_DECL udp_service
31 : : public capy::execution_context::service
32 : , public io_object::io_service
33 : {
34 : public:
35 : /// Identifies this service for `execution_context` lookup.
36 : using key_type = udp_service;
37 :
38 : /** Open a datagram socket.
39 :
40 : Creates a socket and associates it with the platform reactor.
41 :
42 : @param impl The socket implementation to open.
43 : @param family Address family (e.g. `AF_INET`, `AF_INET6`).
44 : @param type Socket type (`SOCK_DGRAM`).
45 : @param protocol Protocol number (`IPPROTO_UDP`).
46 : @return Error code on failure, empty on success.
47 : */
48 : virtual std::error_code open_datagram_socket(
49 : udp_socket::implementation& impl,
50 : int family,
51 : int type,
52 : int protocol) = 0;
53 :
54 : /** Bind a datagram socket to a local endpoint.
55 :
56 : @param impl The socket implementation to bind.
57 : @param ep The local endpoint to bind to.
58 : @return Error code on failure, empty on success.
59 : */
60 : virtual std::error_code
61 : bind_datagram(udp_socket::implementation& impl, endpoint ep) = 0;
62 :
63 : protected:
64 : /// Construct the UDP service.
65 HIT 466 : udp_service() = default;
66 :
67 : /// Destroy the UDP service.
68 466 : ~udp_service() override = default;
69 : };
70 :
71 : } // namespace boost::corosio::detail
72 :
73 : #endif // BOOST_COROSIO_DETAIL_UDP_SERVICE_HPP
|