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