src/corosio/src/socket_option.cpp
100.0% Lines (141/141)
100.0% List of functions (45/45)
100.0% Branches (12/12)
Functions (45)
Function
Calls
Lines
Branches
Blocks
boost::corosio::socket_option::no_delay::level(boost::corosio::family) const
:20
66x
100.0%
–
100.0%
boost::corosio::socket_option::no_delay::name(boost::corosio::family) const
:25
66x
100.0%
–
100.0%
boost::corosio::socket_option::keep_alive::level(boost::corosio::family) const
:33
20x
100.0%
–
100.0%
boost::corosio::socket_option::keep_alive::name(boost::corosio::family) const
:38
20x
100.0%
–
100.0%
boost::corosio::socket_option::v6_only::level(boost::corosio::family) const
:46
34x
100.0%
–
100.0%
boost::corosio::socket_option::v6_only::name(boost::corosio::family) const
:51
34x
100.0%
–
100.0%
boost::corosio::socket_option::reuse_address::level(boost::corosio::family) const
:59
2326x
100.0%
–
100.0%
boost::corosio::socket_option::reuse_address::name(boost::corosio::family) const
:64
2326x
100.0%
–
100.0%
boost::corosio::socket_option::broadcast::level(boost::corosio::family) const
:72
10x
100.0%
–
100.0%
boost::corosio::socket_option::broadcast::name(boost::corosio::family) const
:77
10x
100.0%
–
100.0%
boost::corosio::socket_option::reuse_port::level(boost::corosio::family) const
:86
4x
100.0%
–
100.0%
boost::corosio::socket_option::reuse_port::name(boost::corosio::family) const
:91
4x
100.0%
–
100.0%
boost::corosio::socket_option::receive_buffer_size::level(boost::corosio::family) const
:111
55x
100.0%
–
100.0%
boost::corosio::socket_option::receive_buffer_size::name(boost::corosio::family) const
:116
55x
100.0%
–
100.0%
boost::corosio::socket_option::send_buffer_size::level(boost::corosio::family) const
:124
56x
100.0%
–
100.0%
boost::corosio::socket_option::send_buffer_size::name(boost::corosio::family) const
:129
56x
100.0%
–
100.0%
boost::corosio::socket_option::linger::linger(bool, int)
:136
6288x
100.0%
–
100.0%
boost::corosio::socket_option::linger::enabled() const
:146
16x
100.0%
–
100.0%
boost::corosio::socket_option::linger::enabled(bool)
:154
2x
100.0%
–
100.0%
boost::corosio::socket_option::linger::timeout() const
:163
14x
100.0%
–
100.0%
boost::corosio::socket_option::linger::timeout(int)
:171
2x
100.0%
–
100.0%
boost::corosio::socket_option::linger::level(boost::corosio::family) const
:180
3158x
100.0%
–
100.0%
boost::corosio::socket_option::linger::name(boost::corosio::family) const
:185
3158x
100.0%
–
100.0%
boost::corosio::socket_option::linger::size(boost::corosio::family) const
:191
3158x
100.0%
–
100.0%
boost::corosio::socket_option::multicast_loop::level(boost::corosio::family) const
:198
34x
100.0%
–
100.0%
boost::corosio::socket_option::multicast_loop::name(boost::corosio::family) const
:203
34x
100.0%
–
100.0%
boost::corosio::socket_option::multicast_hops::level(boost::corosio::family) const
:210
16x
100.0%
–
100.0%
boost::corosio::socket_option::multicast_hops::name(boost::corosio::family) const
:215
16x
100.0%
–
100.0%
boost::corosio::socket_option::join_group::join_group(boost::corosio::ip_address const&)
:230
8x
100.0%
–
100.0%
boost::corosio::socket_option::join_group::join_group(boost::corosio::ipv4_address, boost::corosio::ipv4_address)
:238
8x
100.0%
–
100.0%
boost::corosio::socket_option::join_group::join_group(boost::corosio::ipv6_address const&, unsigned int)
:245
4x
100.0%
–
100.0%
boost::corosio::socket_option::join_group::level(boost::corosio::family) const
:254
30x
100.0%
100.0%
100.0%
boost::corosio::socket_option::join_group::name(boost::corosio::family) const
:261
18x
100.0%
100.0%
100.0%
boost::corosio::socket_option::join_group::size(boost::corosio::family) const
:268
30x
100.0%
100.0%
100.0%
boost::corosio::socket_option::leave_group::leave_group(boost::corosio::ip_address const&)
:275
4x
100.0%
–
100.0%
boost::corosio::socket_option::leave_group::leave_group(boost::corosio::ipv4_address, boost::corosio::ipv4_address)
:283
4x
100.0%
–
100.0%
boost::corosio::socket_option::leave_group::leave_group(boost::corosio::ipv6_address const&, unsigned int)
:290
4x
100.0%
–
100.0%
boost::corosio::socket_option::leave_group::level(boost::corosio::family) const
:299
14x
100.0%
100.0%
100.0%
boost::corosio::socket_option::leave_group::name(boost::corosio::family) const
:306
14x
100.0%
100.0%
100.0%
boost::corosio::socket_option::leave_group::size(boost::corosio::family) const
:313
22x
100.0%
100.0%
100.0%
boost::corosio::socket_option::multicast_interface::multicast_interface(boost::corosio::ipv4_address)
:322
8x
100.0%
–
100.0%
boost::corosio::socket_option::multicast_interface::address() const
:330
2x
100.0%
–
100.0%
boost::corosio::socket_option::multicast_interface::level(boost::corosio::family) const
:338
4x
100.0%
–
100.0%
boost::corosio::socket_option::multicast_interface::name(boost::corosio::family) const
:343
4x
100.0%
–
100.0%
boost::corosio::socket_option::multicast_interface::size(boost::corosio::family) const
:348
8x
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 | #include <boost/corosio/socket_option.hpp> | |||
| 11 | #include <boost/corosio/native/native_socket_option.hpp> | |||
| 12 | ||||
| 13 | #include <cstring> | |||
| 14 | ||||
| 15 | namespace boost::corosio::socket_option { | |||
| 16 | ||||
| 17 | // no_delay | |||
| 18 | ||||
| 19 | int | |||
| 20 | 66x | no_delay::level(family f) const noexcept | ||
| 21 | { | |||
| 22 | 66x | return native_socket_option::no_delay{}.level(f); | ||
| 23 | } | |||
| 24 | int | |||
| 25 | 66x | no_delay::name(family f) const noexcept | ||
| 26 | { | |||
| 27 | 66x | return native_socket_option::no_delay{}.name(f); | ||
| 28 | } | |||
| 29 | ||||
| 30 | // keep_alive | |||
| 31 | ||||
| 32 | int | |||
| 33 | 20x | keep_alive::level(family f) const noexcept | ||
| 34 | { | |||
| 35 | 20x | return native_socket_option::keep_alive{}.level(f); | ||
| 36 | } | |||
| 37 | int | |||
| 38 | 20x | keep_alive::name(family f) const noexcept | ||
| 39 | { | |||
| 40 | 20x | return native_socket_option::keep_alive{}.name(f); | ||
| 41 | } | |||
| 42 | ||||
| 43 | // v6_only | |||
| 44 | ||||
| 45 | int | |||
| 46 | 34x | v6_only::level(family f) const noexcept | ||
| 47 | { | |||
| 48 | 34x | return native_socket_option::v6_only{}.level(f); | ||
| 49 | } | |||
| 50 | int | |||
| 51 | 34x | v6_only::name(family f) const noexcept | ||
| 52 | { | |||
| 53 | 34x | return native_socket_option::v6_only{}.name(f); | ||
| 54 | } | |||
| 55 | ||||
| 56 | // reuse_address | |||
| 57 | ||||
| 58 | int | |||
| 59 | 2326x | reuse_address::level(family f) const noexcept | ||
| 60 | { | |||
| 61 | 2326x | return native_socket_option::reuse_address{}.level(f); | ||
| 62 | } | |||
| 63 | int | |||
| 64 | 2326x | reuse_address::name(family f) const noexcept | ||
| 65 | { | |||
| 66 | 2326x | return native_socket_option::reuse_address{}.name(f); | ||
| 67 | } | |||
| 68 | ||||
| 69 | // broadcast | |||
| 70 | ||||
| 71 | int | |||
| 72 | 10x | broadcast::level(family f) const noexcept | ||
| 73 | { | |||
| 74 | 10x | return native_socket_option::broadcast{}.level(f); | ||
| 75 | } | |||
| 76 | int | |||
| 77 | 10x | broadcast::name(family f) const noexcept | ||
| 78 | { | |||
| 79 | 10x | return native_socket_option::broadcast{}.name(f); | ||
| 80 | } | |||
| 81 | ||||
| 82 | // reuse_port | |||
| 83 | ||||
| 84 | #ifdef SO_REUSEPORT | |||
| 85 | int | |||
| 86 | 4x | reuse_port::level(family f) const noexcept | ||
| 87 | { | |||
| 88 | 4x | return native_socket_option::reuse_port{}.level(f); | ||
| 89 | } | |||
| 90 | int | |||
| 91 | 4x | reuse_port::name(family f) const noexcept | ||
| 92 | { | |||
| 93 | 4x | return native_socket_option::reuse_port{}.name(f); | ||
| 94 | } | |||
| 95 | #else | |||
| 96 | int | |||
| 97 | reuse_port::level(family) const noexcept | |||
| 98 | { | |||
| 99 | return SOL_SOCKET; | |||
| 100 | } | |||
| 101 | int | |||
| 102 | reuse_port::name(family) const noexcept | |||
| 103 | { | |||
| 104 | return -1; | |||
| 105 | } | |||
| 106 | #endif | |||
| 107 | ||||
| 108 | // receive_buffer_size | |||
| 109 | ||||
| 110 | int | |||
| 111 | 55x | receive_buffer_size::level(family f) const noexcept | ||
| 112 | { | |||
| 113 | 55x | return native_socket_option::receive_buffer_size{}.level(f); | ||
| 114 | } | |||
| 115 | int | |||
| 116 | 55x | receive_buffer_size::name(family f) const noexcept | ||
| 117 | { | |||
| 118 | 55x | return native_socket_option::receive_buffer_size{}.name(f); | ||
| 119 | } | |||
| 120 | ||||
| 121 | // send_buffer_size | |||
| 122 | ||||
| 123 | int | |||
| 124 | 56x | send_buffer_size::level(family f) const noexcept | ||
| 125 | { | |||
| 126 | 56x | return native_socket_option::send_buffer_size{}.level(f); | ||
| 127 | } | |||
| 128 | int | |||
| 129 | 56x | send_buffer_size::name(family f) const noexcept | ||
| 130 | { | |||
| 131 | 56x | return native_socket_option::send_buffer_size{}.name(f); | ||
| 132 | } | |||
| 133 | ||||
| 134 | // linger | |||
| 135 | ||||
| 136 | 6288x | linger::linger(bool enabled, int timeout) noexcept | ||
| 137 | 3144x | { | ||
| 138 | 3144x | native_socket_option::linger native(enabled, timeout); | ||
| 139 | static_assert( | |||
| 140 | sizeof(native) <= sizeof(storage_), | |||
| 141 | "platform linger exceeds socket_option::linger storage"); | |||
| 142 | 3144x | std::memcpy(storage_, native.data(family::v4), native.size(family::v4)); | ||
| 143 | 3144x | } | ||
| 144 | ||||
| 145 | bool | |||
| 146 | 16x | linger::enabled() const noexcept | ||
| 147 | { | |||
| 148 | 16x | native_socket_option::linger native; | ||
| 149 | 16x | std::memcpy(native.data(family::v4), storage_, native.size(family::v4)); | ||
| 150 | 16x | return native.enabled(); | ||
| 151 | } | |||
| 152 | ||||
| 153 | void | |||
| 154 | 2x | linger::enabled(bool e) noexcept | ||
| 155 | { | |||
| 156 | 2x | native_socket_option::linger native; | ||
| 157 | 2x | std::memcpy(native.data(family::v4), storage_, native.size(family::v4)); | ||
| 158 | 2x | native.enabled(e); | ||
| 159 | 2x | std::memcpy(storage_, native.data(family::v4), native.size(family::v4)); | ||
| 160 | 2x | } | ||
| 161 | ||||
| 162 | int | |||
| 163 | 14x | linger::timeout() const noexcept | ||
| 164 | { | |||
| 165 | 14x | native_socket_option::linger native; | ||
| 166 | 14x | std::memcpy(native.data(family::v4), storage_, native.size(family::v4)); | ||
| 167 | 14x | return native.timeout(); | ||
| 168 | } | |||
| 169 | ||||
| 170 | void | |||
| 171 | 2x | linger::timeout(int t) noexcept | ||
| 172 | { | |||
| 173 | 2x | native_socket_option::linger native; | ||
| 174 | 2x | std::memcpy(native.data(family::v4), storage_, native.size(family::v4)); | ||
| 175 | 2x | native.timeout(t); | ||
| 176 | 2x | std::memcpy(storage_, native.data(family::v4), native.size(family::v4)); | ||
| 177 | 2x | } | ||
| 178 | ||||
| 179 | int | |||
| 180 | 3158x | linger::level(family f) const noexcept | ||
| 181 | { | |||
| 182 | 3158x | return native_socket_option::linger{}.level(f); | ||
| 183 | } | |||
| 184 | int | |||
| 185 | 3158x | linger::name(family f) const noexcept | ||
| 186 | { | |||
| 187 | 3158x | return native_socket_option::linger{}.name(f); | ||
| 188 | } | |||
| 189 | ||||
| 190 | std::size_t | |||
| 191 | 3158x | linger::size(family f) const noexcept | ||
| 192 | { | |||
| 193 | 3158x | return native_socket_option::linger{}.size(f); | ||
| 194 | } | |||
| 195 | ||||
| 196 | // multicast_loop | |||
| 197 | int | |||
| 198 | 34x | multicast_loop::level(family f) const noexcept | ||
| 199 | { | |||
| 200 | 34x | return native_socket_option::multicast_loop{}.level(f); | ||
| 201 | } | |||
| 202 | int | |||
| 203 | 34x | multicast_loop::name(family f) const noexcept | ||
| 204 | { | |||
| 205 | 34x | return native_socket_option::multicast_loop{}.name(f); | ||
| 206 | } | |||
| 207 | ||||
| 208 | // multicast_hops | |||
| 209 | int | |||
| 210 | 16x | multicast_hops::level(family f) const noexcept | ||
| 211 | { | |||
| 212 | 16x | return native_socket_option::multicast_hops{}.level(f); | ||
| 213 | } | |||
| 214 | int | |||
| 215 | 16x | multicast_hops::name(family f) const noexcept | ||
| 216 | { | |||
| 217 | 16x | return native_socket_option::multicast_hops{}.name(f); | ||
| 218 | } | |||
| 219 | ||||
| 220 | // join_group / leave_group | |||
| 221 | // | |||
| 222 | // The public classes mirror the native membership_request: the | |||
| 223 | // group's family picks the wire struct copied into storage_ and the | |||
| 224 | // constants reported by level()/name()/size(). | |||
| 225 | ||||
| 226 | // The membership wire structs must fit both types' opaque storage | |||
| 227 | static_assert(sizeof(struct ip_mreq) <= 20); | |||
| 228 | static_assert(sizeof(struct ipv6_mreq) <= 20); | |||
| 229 | ||||
| 230 | 8x | join_group::join_group(ip_address const& group) noexcept | ||
| 231 | : group_family_(group.family()) | |||
| 232 | 4x | { | ||
| 233 | 4x | native_socket_option::join_group native(group); | ||
| 234 | 8x | std::memcpy( | ||
| 235 | 8x | storage_, native.data(group_family_), native.size(group_family_)); | ||
| 236 | 4x | } | ||
| 237 | ||||
| 238 | 8x | join_group::join_group(ipv4_address group, ipv4_address iface) noexcept | ||
| 239 | : group_family_(family::v4) | |||
| 240 | 4x | { | ||
| 241 | 4x | native_socket_option::join_group native(group, iface); | ||
| 242 | 4x | std::memcpy(storage_, native.data(family::v4), native.size(family::v4)); | ||
| 243 | 4x | } | ||
| 244 | ||||
| 245 | 4x | join_group::join_group( | ||
| 246 | ipv6_address const& group, unsigned int if_index) noexcept | |||
| 247 | : group_family_(family::v6) | |||
| 248 | 2x | { | ||
| 249 | 2x | native_socket_option::join_group native(group, if_index); | ||
| 250 | 2x | std::memcpy(storage_, native.data(family::v6), native.size(family::v6)); | ||
| 251 | 2x | } | ||
| 252 | ||||
| 253 | int | |||
| 254 | 30x | join_group::level(family f) const noexcept | ||
| 255 | { | |||
| 256 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 16 times.
|
30x | return group_family_ == family::v4 | |
| 257 | 16x | ? native_socket_option::join_group(ipv4_address()).level(f) | ||
| 258 | 14x | : native_socket_option::join_group(ipv6_address()).level(f); | ||
| 259 | } | |||
| 260 | int | |||
| 261 | 18x | join_group::name(family f) const noexcept | ||
| 262 | { | |||
| 263 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 10 times.
|
18x | return group_family_ == family::v4 | |
| 264 | 10x | ? native_socket_option::join_group(ipv4_address()).name(f) | ||
| 265 | 8x | : native_socket_option::join_group(ipv6_address()).name(f); | ||
| 266 | } | |||
| 267 | std::size_t | |||
| 268 | 30x | join_group::size(family f) const noexcept | ||
| 269 | { | |||
| 270 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 16 times.
|
30x | return group_family_ == family::v4 | |
| 271 | 16x | ? native_socket_option::join_group(ipv4_address()).size(f) | ||
| 272 | 14x | : native_socket_option::join_group(ipv6_address()).size(f); | ||
| 273 | } | |||
| 274 | ||||
| 275 | 4x | leave_group::leave_group(ip_address const& group) noexcept | ||
| 276 | : group_family_(group.family()) | |||
| 277 | 2x | { | ||
| 278 | 2x | native_socket_option::leave_group native(group); | ||
| 279 | 4x | std::memcpy( | ||
| 280 | 4x | storage_, native.data(group_family_), native.size(group_family_)); | ||
| 281 | 2x | } | ||
| 282 | ||||
| 283 | 4x | leave_group::leave_group(ipv4_address group, ipv4_address iface) noexcept | ||
| 284 | : group_family_(family::v4) | |||
| 285 | 2x | { | ||
| 286 | 2x | native_socket_option::leave_group native(group, iface); | ||
| 287 | 2x | std::memcpy(storage_, native.data(family::v4), native.size(family::v4)); | ||
| 288 | 2x | } | ||
| 289 | ||||
| 290 | 4x | leave_group::leave_group( | ||
| 291 | ipv6_address const& group, unsigned int if_index) noexcept | |||
| 292 | : group_family_(family::v6) | |||
| 293 | 2x | { | ||
| 294 | 2x | native_socket_option::leave_group native(group, if_index); | ||
| 295 | 2x | std::memcpy(storage_, native.data(family::v6), native.size(family::v6)); | ||
| 296 | 2x | } | ||
| 297 | ||||
| 298 | int | |||
| 299 | 14x | leave_group::level(family f) const noexcept | ||
| 300 | { | |||
| 301 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8 times.
|
14x | return group_family_ == family::v4 | |
| 302 | 8x | ? native_socket_option::leave_group(ipv4_address()).level(f) | ||
| 303 | 6x | : native_socket_option::leave_group(ipv6_address()).level(f); | ||
| 304 | } | |||
| 305 | int | |||
| 306 | 14x | leave_group::name(family f) const noexcept | ||
| 307 | { | |||
| 308 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8 times.
|
14x | return group_family_ == family::v4 | |
| 309 | 8x | ? native_socket_option::leave_group(ipv4_address()).name(f) | ||
| 310 | 6x | : native_socket_option::leave_group(ipv6_address()).name(f); | ||
| 311 | } | |||
| 312 | std::size_t | |||
| 313 | 22x | leave_group::size(family f) const noexcept | ||
| 314 | { | |||
| 315 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 12 times.
|
22x | return group_family_ == family::v4 | |
| 316 | 12x | ? native_socket_option::leave_group(ipv4_address()).size(f) | ||
| 317 | 10x | : native_socket_option::leave_group(ipv6_address()).size(f); | ||
| 318 | } | |||
| 319 | ||||
| 320 | // multicast_interface | |||
| 321 | ||||
| 322 | 8x | multicast_interface::multicast_interface(ipv4_address iface) noexcept | ||
| 323 | 4x | { | ||
| 324 | 4x | native_socket_option::multicast_interface native(iface); | ||
| 325 | static_assert(sizeof(struct in_addr) <= sizeof(v4_storage_)); | |||
| 326 | 4x | std::memcpy(v4_storage_, native.data(family::v4), native.size(family::v4)); | ||
| 327 | 4x | } | ||
| 328 | ||||
| 329 | ipv4_address | |||
| 330 | 2x | multicast_interface::address() const noexcept | ||
| 331 | { | |||
| 332 | ipv4_address::bytes_type b; | |||
| 333 | 2x | std::memcpy(b.data(), v4_storage_, 4); | ||
| 334 | 2x | return ipv4_address(b); | ||
| 335 | } | |||
| 336 | ||||
| 337 | int | |||
| 338 | 4x | multicast_interface::level(family f) const noexcept | ||
| 339 | { | |||
| 340 | 4x | return native_socket_option::multicast_interface{}.level(f); | ||
| 341 | } | |||
| 342 | int | |||
| 343 | 4x | multicast_interface::name(family f) const noexcept | ||
| 344 | { | |||
| 345 | 4x | return native_socket_option::multicast_interface{}.name(f); | ||
| 346 | } | |||
| 347 | std::size_t | |||
| 348 | 8x | multicast_interface::size(family f) const noexcept | ||
| 349 | { | |||
| 350 | 8x | return native_socket_option::multicast_interface{}.size(f); | ||
| 351 | } | |||
| 352 | ||||
| 353 | } // namespace boost::corosio::socket_option | |||
| 354 |