src/corosio/src/socket_option.cpp

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