src/corosio/src/local_stream_socket.cpp
94.9% Lines (56/59)
100.0% List of functions (13/13)
87.0% Branches (20/23)
Functions (13)
Function
Calls
Lines
Branches
Blocks
boost::corosio::local_stream_socket::~local_stream_socket()
:26
88x
0.0%
–
100.0%
boost::corosio::local_stream_socket::local_stream_socket(boost::capy::execution_context&)
:31
66x
100.0%
100.0%
100.0%
boost::corosio::local_stream_socket::open(boost::corosio::local_stream)
:37
21x
75.0%
50.0%
87.5%
boost::corosio::local_stream_socket::open_for_family(int, int, int)
:45
21x
100.0%
–
100.0%
boost::corosio::local_stream_socket::close()
:55
92x
100.0%
100.0%
100.0%
boost::corosio::local_stream_socket::cancel()
:63
3x
100.0%
100.0%
100.0%
boost::corosio::local_stream_socket::shutdown(boost::corosio::shutdown_type)
:71
3x
100.0%
100.0%
100.0%
boost::corosio::local_stream_socket::assign(unsigned long long)
:79
30x
100.0%
–
100.0%
boost::corosio::local_stream_socket::native_handle() const
:88
4x
100.0%
100.0%
100.0%
boost::corosio::local_stream_socket::release()
:100
3x
100.0%
100.0%
100.0%
boost::corosio::local_stream_socket::available() const
:110
3x
80.0%
66.7%
73.3%
boost::corosio::local_stream_socket::local_endpoint() const
:135
3x
100.0%
100.0%
100.0%
boost::corosio::local_stream_socket::remote_endpoint() const
:143
3x
100.0%
100.0%
100.0%
| Line | Branch | TLA | Hits | Source Code |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Copyright (c) 2026 Michael Vandeberg | |||
| 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/detail/platform.hpp> | |||
| 11 | ||||
| 12 | #if BOOST_COROSIO_POSIX || BOOST_COROSIO_HAS_IOCP | |||
| 13 | ||||
| 14 | #include <boost/corosio/local_stream_socket.hpp> | |||
| 15 | #include <boost/corosio/detail/except.hpp> | |||
| 16 | #include <boost/corosio/detail/local_stream_service.hpp> | |||
| 17 | ||||
| 18 | #if BOOST_COROSIO_POSIX | |||
| 19 | #include <sys/ioctl.h> | |||
| 20 | #elif BOOST_COROSIO_HAS_IOCP | |||
| 21 | #include <boost/corosio/native/detail/iocp/win_windows.hpp> | |||
| 22 | #endif | |||
| 23 | ||||
| 24 | namespace boost::corosio { | |||
| 25 | ||||
| 26 | 88x | local_stream_socket::~local_stream_socket() | ||
| 27 | { | |||
| 28 | 88x | close(); | ||
| 29 | 88x | } | ||
| 30 | ||||
| 31 | 66x | local_stream_socket::local_stream_socket(capy::execution_context& ctx) | ||
| 32 |
1/1✓ Branch 2 → 3 taken 66 times.
|
66x | : io_object(create_handle<detail::local_stream_service>(ctx)) | |
| 33 | { | |||
| 34 | 66x | } | ||
| 35 | ||||
| 36 | std::error_code | |||
| 37 | 21x | local_stream_socket::open(local_stream proto) noexcept | ||
| 38 | { | |||
| 39 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 21 times.
|
21x | if (is_open()) | |
| 40 | ✗ | return {}; | ||
| 41 | 21x | return open_for_family(proto.family(), proto.type(), proto.protocol()); | ||
| 42 | } | |||
| 43 | ||||
| 44 | std::error_code | |||
| 45 | 21x | local_stream_socket::open_for_family(int family, int type, int protocol) noexcept | ||
| 46 | { | |||
| 47 | 21x | auto& svc = static_cast<detail::local_stream_service&>(h_.service()); | ||
| 48 | 21x | std::error_code ec = svc.open_socket( | ||
| 49 | 21x | static_cast<local_stream_socket::implementation&>(*h_.get()), | ||
| 50 | family, type, protocol); | |||
| 51 | 21x | return ec; | ||
| 52 | } | |||
| 53 | ||||
| 54 | void | |||
| 55 | 92x | local_stream_socket::close() noexcept | ||
| 56 | { | |||
| 57 |
2/2✓ Branch 3 → 4 taken 32 times.
✓ Branch 3 → 5 taken 60 times.
|
92x | if (!is_open()) | |
| 58 | 32x | return; | ||
| 59 | 60x | h_.service().close(h_); | ||
| 60 | } | |||
| 61 | ||||
| 62 | void | |||
| 63 | 3x | local_stream_socket::cancel() noexcept | ||
| 64 | { | |||
| 65 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 2 times.
|
3x | if (!is_open()) | |
| 66 | 1x | return; | ||
| 67 | 2x | get().cancel(); | ||
| 68 | } | |||
| 69 | ||||
| 70 | std::error_code | |||
| 71 | 3x | local_stream_socket::shutdown(shutdown_type what) noexcept | ||
| 72 | { | |||
| 73 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 2 times.
|
3x | if (!is_open()) | |
| 74 | 1x | return make_error_code(std::errc::bad_file_descriptor); | ||
| 75 | 2x | return get().shutdown(what); | ||
| 76 | } | |||
| 77 | ||||
| 78 | std::error_code | |||
| 79 | 30x | local_stream_socket::assign(native_handle_type fd) noexcept | ||
| 80 | { | |||
| 81 | 30x | auto& svc = static_cast<detail::local_stream_service&>(h_.service()); | ||
| 82 | 30x | std::error_code ec = svc.assign_socket( | ||
| 83 | 30x | static_cast<local_stream_socket::implementation&>(*h_.get()), fd); | ||
| 84 | 30x | return ec; | ||
| 85 | } | |||
| 86 | ||||
| 87 | native_handle_type | |||
| 88 | 4x | local_stream_socket::native_handle() const noexcept | ||
| 89 | { | |||
| 90 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 3 times.
|
4x | if (!is_open()) | |
| 91 | #if BOOST_COROSIO_HAS_IOCP | |||
| 92 | 1x | return ~native_handle_type(0); | ||
| 93 | #else | |||
| 94 | return -1; | |||
| 95 | #endif | |||
| 96 | 3x | return get().native_handle(); | ||
| 97 | } | |||
| 98 | ||||
| 99 | native_handle_type | |||
| 100 | 3x | local_stream_socket::release() | ||
| 101 | { | |||
| 102 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 6 taken 2 times.
|
3x | if (!is_open()) | |
| 103 | 1x | detail::throw_system_error( | ||
| 104 | 1x | make_error_code(std::errc::bad_file_descriptor), | ||
| 105 | "local_stream_socket::release"); | |||
| 106 | 2x | return get().release_socket(); | ||
| 107 | } | |||
| 108 | ||||
| 109 | std::size_t | |||
| 110 | 3x | local_stream_socket::available() const | ||
| 111 | { | |||
| 112 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 6 taken 2 times.
|
3x | if (!is_open()) | |
| 113 | 1x | detail::throw_system_error( | ||
| 114 | 2x | make_error_code(std::errc::bad_file_descriptor), | ||
| 115 | "local_stream_socket::available"); | |||
| 116 | #if BOOST_COROSIO_HAS_IOCP | |||
| 117 | 2x | u_long value = 0; | ||
| 118 |
1/1✓ Branch 7 → 8 taken 2 times.
|
2x | if (::ioctlsocket( | |
| 119 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 12 taken 2 times.
|
4x | static_cast<SOCKET>(native_handle()), FIONREAD, &value) != 0) | |
| 120 | ✗ | detail::throw_system_error( | ||
| 121 | ✗ | std::error_code(::WSAGetLastError(), std::system_category()), | ||
| 122 | "local_stream_socket::available"); | |||
| 123 | 2x | return static_cast<std::size_t>(value); | ||
| 124 | #else | |||
| 125 | int value = 0; | |||
| 126 | if (::ioctl(native_handle(), FIONREAD, &value) < 0) | |||
| 127 | detail::throw_system_error( | |||
| 128 | std::error_code(errno, std::system_category()), | |||
| 129 | "local_stream_socket::available"); | |||
| 130 | return static_cast<std::size_t>(value); | |||
| 131 | #endif | |||
| 132 | } | |||
| 133 | ||||
| 134 | local_endpoint | |||
| 135 | 3x | local_stream_socket::local_endpoint() const noexcept | ||
| 136 | { | |||
| 137 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 2 times.
|
3x | if (!is_open()) | |
| 138 | 1x | return corosio::local_endpoint{}; | ||
| 139 | 2x | return get().local_endpoint(); | ||
| 140 | } | |||
| 141 | ||||
| 142 | local_endpoint | |||
| 143 | 3x | local_stream_socket::remote_endpoint() const noexcept | ||
| 144 | { | |||
| 145 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 2 times.
|
3x | if (!is_open()) | |
| 146 | 1x | return corosio::local_endpoint{}; | ||
| 147 | 2x | return get().remote_endpoint(); | ||
| 148 | } | |||
| 149 | ||||
| 150 | } // namespace boost::corosio | |||
| 151 | ||||
| 152 | #endif // BOOST_COROSIO_POSIX || BOOST_COROSIO_HAS_IOCP | |||
| 153 |