src/corosio/src/socket_option.cpp
95.2% Lines (40/42)
90.9% Functions (20/22)
| 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 | 42 | int no_delay::level() noexcept { return native_socket_option::no_delay::level(); } | |
| 20 | 42 | int no_delay::name() noexcept { return native_socket_option::no_delay::name(); } | |
| 21 | |||
| 22 | // keep_alive | ||
| 23 | |||
| 24 | 16 | int keep_alive::level() noexcept { return native_socket_option::keep_alive::level(); } | |
| 25 | 16 | int keep_alive::name() noexcept { return native_socket_option::keep_alive::name(); } | |
| 26 | |||
| 27 | // v6_only | ||
| 28 | |||
| 29 | 14 | int v6_only::level() noexcept { return native_socket_option::v6_only::level(); } | |
| 30 | 14 | int v6_only::name() noexcept { return native_socket_option::v6_only::name(); } | |
| 31 | |||
| 32 | // reuse_address | ||
| 33 | |||
| 34 | 135 | int reuse_address::level() noexcept { return native_socket_option::reuse_address::level(); } | |
| 35 | 135 | int reuse_address::name() noexcept { return native_socket_option::reuse_address::name(); } | |
| 36 | |||
| 37 | // reuse_port | ||
| 38 | |||
| 39 | #ifdef SO_REUSEPORT | ||
| 40 | ✗ | int reuse_port::level() noexcept { return native_socket_option::reuse_port::level(); } | |
| 41 | ✗ | int reuse_port::name() noexcept { return native_socket_option::reuse_port::name(); } | |
| 42 | #else | ||
| 43 | int reuse_port::level() noexcept { return SOL_SOCKET; } | ||
| 44 | int reuse_port::name() noexcept { return -1; } | ||
| 45 | #endif | ||
| 46 | |||
| 47 | // receive_buffer_size | ||
| 48 | |||
| 49 | 16 | int receive_buffer_size::level() noexcept { return native_socket_option::receive_buffer_size::level(); } | |
| 50 | 16 | int receive_buffer_size::name() noexcept { return native_socket_option::receive_buffer_size::name(); } | |
| 51 | |||
| 52 | // send_buffer_size | ||
| 53 | |||
| 54 | 8 | int send_buffer_size::level() noexcept { return native_socket_option::send_buffer_size::level(); } | |
| 55 | 8 | int send_buffer_size::name() noexcept { return native_socket_option::send_buffer_size::name(); } | |
| 56 | |||
| 57 | // linger | ||
| 58 | |||
| 59 | 16 | linger::linger( bool enabled, int timeout ) noexcept | |
| 60 | { | ||
| 61 | 16 | native_socket_option::linger native( enabled, timeout ); | |
| 62 | static_assert( | ||
| 63 | sizeof( native ) <= sizeof( storage_ ), | ||
| 64 | "platform linger exceeds socket_option::linger storage" ); | ||
| 65 | 16 | std::memcpy( storage_, native.data(), native.size() ); | |
| 66 | 16 | } | |
| 67 | |||
| 68 | bool | ||
| 69 | 14 | linger::enabled() const noexcept | |
| 70 | { | ||
| 71 | 14 | native_socket_option::linger native; | |
| 72 | 14 | std::memcpy( native.data(), storage_, native.size() ); | |
| 73 | 14 | return native.enabled(); | |
| 74 | } | ||
| 75 | |||
| 76 | void | ||
| 77 | 2 | linger::enabled( bool e ) noexcept | |
| 78 | { | ||
| 79 | 2 | native_socket_option::linger native; | |
| 80 | 2 | std::memcpy( native.data(), storage_, native.size() ); | |
| 81 | 2 | native.enabled( e ); | |
| 82 | 2 | std::memcpy( storage_, native.data(), native.size() ); | |
| 83 | 2 | } | |
| 84 | |||
| 85 | int | ||
| 86 | 12 | linger::timeout() const noexcept | |
| 87 | { | ||
| 88 | 12 | native_socket_option::linger native; | |
| 89 | 12 | std::memcpy( native.data(), storage_, native.size() ); | |
| 90 | 12 | return native.timeout(); | |
| 91 | } | ||
| 92 | |||
| 93 | void | ||
| 94 | 2 | linger::timeout( int t ) noexcept | |
| 95 | { | ||
| 96 | 2 | native_socket_option::linger native; | |
| 97 | 2 | std::memcpy( native.data(), storage_, native.size() ); | |
| 98 | 2 | native.timeout( t ); | |
| 99 | 2 | std::memcpy( storage_, native.data(), native.size() ); | |
| 100 | 2 | } | |
| 101 | |||
| 102 | 28 | int linger::level() noexcept { return native_socket_option::linger::level(); } | |
| 103 | 28 | int linger::name() noexcept { return native_socket_option::linger::name(); } | |
| 104 | |||
| 105 | std::size_t | ||
| 106 | 28 | linger::size() const noexcept | |
| 107 | { | ||
| 108 | 28 | return native_socket_option::linger{}.size(); | |
| 109 | } | ||
| 110 | |||
| 111 | } // namespace boost::corosio::socket_option | ||
| 112 |