0.00% Lines (0/0)
0.00% Functions (0/0)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | - | // | ||||||
| 2 | - | // Copyright (c) 2026 Steve Gerbino | ||||||
| 3 | - | // Copyright (c) 2026 Michael Vandeberg | ||||||
| 4 | - | // | ||||||
| 5 | - | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||||||
| 6 | - | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||||||
| 7 | - | // | ||||||
| 8 | - | // Official repository: https://github.com/cppalliance/corosio | ||||||
| 9 | - | // | ||||||
| 10 | - | |||||||
| 11 | - | #ifndef BOOST_COROSIO_UDP_HPP | ||||||
| 12 | - | #define BOOST_COROSIO_UDP_HPP | ||||||
| 13 | - | |||||||
| 14 | - | #include <boost/corosio/detail/config.hpp> | ||||||
| 15 | - | |||||||
| 16 | - | namespace boost::corosio { | ||||||
| 17 | - | |||||||
| 18 | - | class udp_socket; | ||||||
| 19 | - | |||||||
| 20 | - | /** Encapsulate the UDP protocol for socket creation. | ||||||
| 21 | - | |||||||
| 22 | - | This class identifies the UDP protocol and its address family | ||||||
| 23 | - | (IPv4 or IPv6). It is used to parameterize `udp_socket::open()` | ||||||
| 24 | - | calls with a self-documenting type. | ||||||
| 25 | - | |||||||
| 26 | - | The `family()`, `type()`, and `protocol()` members return the | ||||||
| 27 | - | three integers passed to the operating system's `socket()` | ||||||
| 28 | - | call. Their values are platform-defined constants taken from | ||||||
| 29 | - | the system socket headers. For an inline variant that includes | ||||||
| 30 | - | those headers, use @ref native_udp. | ||||||
| 31 | - | |||||||
| 32 | - | @par Example | ||||||
| 33 | - | @par !example udp | ||||||
| 34 | - | |||||||
| 35 | - | @see native_udp, udp_socket | ||||||
| 36 | - | */ | ||||||
| 37 | - | class BOOST_COROSIO_DECL udp | ||||||
| 38 | - | { | ||||||
| 39 | - | bool v6_; | ||||||
| DCB | 40 | - | 329 | explicit constexpr udp(bool v6) noexcept : v6_(v6) {} | ||||
| 41 | - | |||||||
| 42 | - | public: | ||||||
| 43 | - | /// Construct an IPv4 UDP protocol. | ||||||
| DCB | 44 | - | 305 | static constexpr udp v4() noexcept | ||||
| 45 | - | { | ||||||
| DCB | 46 | - | 305 | return udp(false); | ||||
| 47 | - | } | ||||||
| 48 | - | |||||||
| 49 | - | /// Construct an IPv6 UDP protocol. | ||||||
| DCB | 50 | - | 24 | static constexpr udp v6() noexcept | ||||
| 51 | - | { | ||||||
| DCB | 52 | - | 24 | return udp(true); | ||||
| 53 | - | } | ||||||
| 54 | - | |||||||
| 55 | - | /// Return true if this is IPv6. | ||||||
| 56 | - | constexpr bool is_v6() const noexcept | ||||||
| 57 | - | { | ||||||
| 58 | - | return v6_; | ||||||
| 59 | - | } | ||||||
| 60 | - | |||||||
| 61 | - | /// Return the address family (AF_INET or AF_INET6). | ||||||
| 62 | - | int family() const noexcept; | ||||||
| 63 | - | |||||||
| 64 | - | /// Return the socket type (SOCK_DGRAM). | ||||||
| 65 | - | static int type() noexcept; | ||||||
| 66 | - | |||||||
| 67 | - | /// Return the IP protocol (IPPROTO_UDP). | ||||||
| 68 | - | static int protocol() noexcept; | ||||||
| 69 | - | |||||||
| 70 | - | /// The socket type to use with this protocol, @ref udp_socket. | ||||||
| 71 | - | using socket = udp_socket; | ||||||
| 72 | - | |||||||
| 73 | - | /// Test for equality. | ||||||
| 74 | - | friend constexpr bool operator==(udp a, udp b) noexcept | ||||||
| 75 | - | { | ||||||
| 76 | - | return a.v6_ == b.v6_; | ||||||
| 77 | - | } | ||||||
| 78 | - | |||||||
| 79 | - | /// Test for inequality. | ||||||
| 80 | - | friend constexpr bool operator!=(udp a, udp b) noexcept | ||||||
| 81 | - | { | ||||||
| 82 | - | return a.v6_ != b.v6_; | ||||||
| 83 | - | } | ||||||
| 84 | - | }; | ||||||
| 85 | - | |||||||
| 86 | - | } // namespace boost::corosio | ||||||
| 87 | - | |||||||
| 88 | - | #endif // BOOST_COROSIO_UDP_HPP | ||||||