include/boost/corosio/detail/udp_service.hpp
100.0% Lines (2 / 2)
-% Branches (0 / 0)
100.0% Functions (2 / 2)
Functions (2)
Function
Calls
Lines
Branches
Blocks
boost::corosio::detail::udp_service::udp_service()
:80
106x
100.0%
–
100.0%
boost::corosio::detail::udp_service::~udp_service()
:83
106x
100.0%
–
100.0%
| Line | Branch | TLA | Hits | 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 | /** Assign an existing native socket handle to a socket. | |||
| 55 | ||||
| 56 | Adopts a pre-created socket handle. On success the impl | |||
| 57 | takes ownership and will close the handle. On failure the | |||
| 58 | caller retains ownership and must close it. If the impl is | |||
| 59 | already open, its pending operations are cancelled and the | |||
| 60 | held socket is closed before the new one is adopted. | |||
| 61 | ||||
| 62 | @param impl The socket implementation to assign to. | |||
| 63 | @param fd The native socket handle to adopt. | |||
| 64 | @return Error code on failure, empty on success. | |||
| 65 | */ | |||
| 66 | virtual std::error_code | |||
| 67 | assign_socket(udp_socket::implementation& impl, native_handle_type fd) = 0; | |||
| 68 | ||||
| 69 | /** Bind a datagram socket to a local endpoint. | |||
| 70 | ||||
| 71 | @param impl The socket implementation to bind. | |||
| 72 | @param ep The local endpoint to bind to. | |||
| 73 | @return Error code on failure, empty on success. | |||
| 74 | */ | |||
| 75 | virtual std::error_code | |||
| 76 | bind_datagram(udp_socket::implementation& impl, endpoint ep) = 0; | |||
| 77 | ||||
| 78 | protected: | |||
| 79 | /// Construct the UDP service. | |||
| 80 | 106x | udp_service() = default; | ||
| 81 | ||||
| 82 | /// Destroy the UDP service. | |||
| 83 | 106x | ~udp_service() override = default; | ||
| 84 | }; | |||
| 85 | ||||
| 86 | } // namespace boost::corosio::detail | |||
| 87 | ||||
| 88 | #endif // BOOST_COROSIO_DETAIL_UDP_SERVICE_HPP | |||
| 89 |