src/corosio/src/socket_option.cpp
100.0% Lines (141 / 141)
100.0% Functions (45 / 45)
Functions (45)
Function
Calls
Lines
Blocks
boost::corosio::socket_option::no_delay::level(boost::corosio::family) const
:20
68x
100.0%
100.0%
boost::corosio::socket_option::no_delay::name(boost::corosio::family) const
:25
68x
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
611x
100.0%
100.0%
boost::corosio::socket_option::reuse_address::name(boost::corosio::family) const
:64
611x
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
57x
100.0%
100.0%
boost::corosio::socket_option::receive_buffer_size::name(boost::corosio::family) const
:116
57x
100.0%
100.0%
boost::corosio::socket_option::send_buffer_size::level(boost::corosio::family) const
:124
74x
100.0%
100.0%
boost::corosio::socket_option::send_buffer_size::name(boost::corosio::family) const
:129
74x
100.0%
100.0%
boost::corosio::socket_option::linger::linger(bool, int)
:136
201x
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
215x
100.0%
100.0%
boost::corosio::socket_option::linger::name(boost::corosio::family) const
:185
215x
100.0%
100.0%
boost::corosio::socket_option::linger::size(boost::corosio::family) const
:191
215x
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
4x
100.0%
100.0%
boost::corosio::socket_option::join_group::join_group(boost::corosio::ipv4_address, boost::corosio::ipv4_address)
:238
4x
100.0%
100.0%
boost::corosio::socket_option::join_group::join_group(boost::corosio::ipv6_address const&, unsigned int)
:245
2x
100.0%
100.0%
boost::corosio::socket_option::join_group::level(boost::corosio::family) const
:254
30x
100.0%
100.0%
boost::corosio::socket_option::join_group::name(boost::corosio::family) const
:261
18x
100.0%
100.0%
boost::corosio::socket_option::join_group::size(boost::corosio::family) const
:268
30x
100.0%
100.0%
boost::corosio::socket_option::leave_group::leave_group(boost::corosio::ip_address const&)
:275
2x
100.0%
100.0%
boost::corosio::socket_option::leave_group::leave_group(boost::corosio::ipv4_address, boost::corosio::ipv4_address)
:283
2x
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
16x
100.0%
100.0%
boost::corosio::socket_option::leave_group::name(boost::corosio::family) const
:306
16x
100.0%
100.0%
boost::corosio::socket_option::leave_group::size(boost::corosio::family) const
:313
24x
100.0%
100.0%
boost::corosio::socket_option::multicast_interface::multicast_interface(boost::corosio::ipv4_address)
:322
4x
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
6x
100.0%
100.0%
boost::corosio::socket_option::multicast_interface::name(boost::corosio::family) const
:343
6x
100.0%
100.0%
boost::corosio::socket_option::multicast_interface::size(boost::corosio::family) const
:348
10x
100.0%
100.0%
| Line | 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 | 68x | no_delay::level(family f) const noexcept | |
| 21 | { | ||
| 22 | 68x | return native_socket_option::no_delay{}.level(f); | |
| 23 | } | ||
| 24 | int | ||
| 25 | 68x | no_delay::name(family f) const noexcept | |
| 26 | { | ||
| 27 | 68x | 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 | 611x | reuse_address::level(family f) const noexcept | |
| 60 | { | ||
| 61 | 611x | return native_socket_option::reuse_address{}.level(f); | |
| 62 | } | ||
| 63 | int | ||
| 64 | 611x | reuse_address::name(family f) const noexcept | |
| 65 | { | ||
| 66 | 611x | 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 | 57x | receive_buffer_size::level(family f) const noexcept | |
| 112 | { | ||
| 113 | 57x | return native_socket_option::receive_buffer_size{}.level(f); | |
| 114 | } | ||
| 115 | int | ||
| 116 | 57x | receive_buffer_size::name(family f) const noexcept | |
| 117 | { | ||
| 118 | 57x | return native_socket_option::receive_buffer_size{}.name(f); | |
| 119 | } | ||
| 120 | |||
| 121 | // send_buffer_size | ||
| 122 | |||
| 123 | int | ||
| 124 | 74x | send_buffer_size::level(family f) const noexcept | |
| 125 | { | ||
| 126 | 74x | return native_socket_option::send_buffer_size{}.level(f); | |
| 127 | } | ||
| 128 | int | ||
| 129 | 74x | send_buffer_size::name(family f) const noexcept | |
| 130 | { | ||
| 131 | 74x | return native_socket_option::send_buffer_size{}.name(f); | |
| 132 | } | ||
| 133 | |||
| 134 | // linger | ||
| 135 | |||
| 136 | 201x | linger::linger(bool enabled, int timeout) noexcept | |
| 137 | { | ||
| 138 | 201x | native_socket_option::linger native(enabled, timeout); | |
| 139 | static_assert( | ||
| 140 | sizeof(native) <= sizeof(storage_), | ||
| 141 | "platform linger exceeds socket_option::linger storage"); | ||
| 142 | 201x | std::memcpy(storage_, native.data(family::v4), native.size(family::v4)); | |
| 143 | 201x | } | |
| 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 | 215x | linger::level(family f) const noexcept | |
| 181 | { | ||
| 182 | 215x | return native_socket_option::linger{}.level(f); | |
| 183 | } | ||
| 184 | int | ||
| 185 | 215x | linger::name(family f) const noexcept | |
| 186 | { | ||
| 187 | 215x | return native_socket_option::linger{}.name(f); | |
| 188 | } | ||
| 189 | |||
| 190 | std::size_t | ||
| 191 | 215x | linger::size(family f) const noexcept | |
| 192 | { | ||
| 193 | 215x | 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 | 4x | join_group::join_group(ip_address const& group) noexcept | |
| 231 | 4x | : group_family_(group.family()) | |
| 232 | { | ||
| 233 | 4x | native_socket_option::join_group native(group); | |
| 234 | 4x | std::memcpy( | |
| 235 | 4x | storage_, native.data(group_family_), native.size(group_family_)); | |
| 236 | 4x | } | |
| 237 | |||
| 238 | 4x | join_group::join_group(ipv4_address group, ipv4_address iface) noexcept | |
| 239 | 4x | : group_family_(family::v4) | |
| 240 | { | ||
| 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 | 2x | join_group::join_group( | |
| 246 | 2x | ipv6_address const& group, unsigned int if_index) noexcept | |
| 247 | 2x | : group_family_(family::v6) | |
| 248 | { | ||
| 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 | 30x | return group_family_ == family::v4 | |
| 257 | 30x | ? native_socket_option::join_group(ipv4_address()).level(f) | |
| 258 | 30x | : native_socket_option::join_group(ipv6_address()).level(f); | |
| 259 | } | ||
| 260 | int | ||
| 261 | 18x | join_group::name(family f) const noexcept | |
| 262 | { | ||
| 263 | 18x | return group_family_ == family::v4 | |
| 264 | 18x | ? native_socket_option::join_group(ipv4_address()).name(f) | |
| 265 | 18x | : 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 | 30x | return group_family_ == family::v4 | |
| 271 | 30x | ? native_socket_option::join_group(ipv4_address()).size(f) | |
| 272 | 30x | : native_socket_option::join_group(ipv6_address()).size(f); | |
| 273 | } | ||
| 274 | |||
| 275 | 2x | leave_group::leave_group(ip_address const& group) noexcept | |
| 276 | 2x | : group_family_(group.family()) | |
| 277 | { | ||
| 278 | 2x | native_socket_option::leave_group native(group); | |
| 279 | 2x | std::memcpy( | |
| 280 | 2x | storage_, native.data(group_family_), native.size(group_family_)); | |
| 281 | 2x | } | |
| 282 | |||
| 283 | 2x | leave_group::leave_group(ipv4_address group, ipv4_address iface) noexcept | |
| 284 | 2x | : group_family_(family::v4) | |
| 285 | { | ||
| 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 | 4x | ipv6_address const& group, unsigned int if_index) noexcept | |
| 292 | 4x | : group_family_(family::v6) | |
| 293 | { | ||
| 294 | 4x | native_socket_option::leave_group native(group, if_index); | |
| 295 | 4x | std::memcpy(storage_, native.data(family::v6), native.size(family::v6)); | |
| 296 | 4x | } | |
| 297 | |||
| 298 | int | ||
| 299 | 16x | leave_group::level(family f) const noexcept | |
| 300 | { | ||
| 301 | 16x | return group_family_ == family::v4 | |
| 302 | 16x | ? native_socket_option::leave_group(ipv4_address()).level(f) | |
| 303 | 16x | : native_socket_option::leave_group(ipv6_address()).level(f); | |
| 304 | } | ||
| 305 | int | ||
| 306 | 16x | leave_group::name(family f) const noexcept | |
| 307 | { | ||
| 308 | 16x | return group_family_ == family::v4 | |
| 309 | 16x | ? native_socket_option::leave_group(ipv4_address()).name(f) | |
| 310 | 16x | : native_socket_option::leave_group(ipv6_address()).name(f); | |
| 311 | } | ||
| 312 | std::size_t | ||
| 313 | 24x | leave_group::size(family f) const noexcept | |
| 314 | { | ||
| 315 | 24x | return group_family_ == family::v4 | |
| 316 | 24x | ? native_socket_option::leave_group(ipv4_address()).size(f) | |
| 317 | 24x | : native_socket_option::leave_group(ipv6_address()).size(f); | |
| 318 | } | ||
| 319 | |||
| 320 | // multicast_interface | ||
| 321 | |||
| 322 | 4x | multicast_interface::multicast_interface(ipv4_address iface) noexcept | |
| 323 | { | ||
| 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 | 6x | multicast_interface::level(family f) const noexcept | |
| 339 | { | ||
| 340 | 6x | return native_socket_option::multicast_interface{}.level(f); | |
| 341 | } | ||
| 342 | int | ||
| 343 | 6x | multicast_interface::name(family f) const noexcept | |
| 344 | { | ||
| 345 | 6x | return native_socket_option::multicast_interface{}.name(f); | |
| 346 | } | ||
| 347 | std::size_t | ||
| 348 | 10x | multicast_interface::size(family f) const noexcept | |
| 349 | { | ||
| 350 | 10x | return native_socket_option::multicast_interface{}.size(f); | |
| 351 | } | ||
| 352 | |||
| 353 | } // namespace boost::corosio::socket_option | ||
| 354 |