src/corosio/src/posix_stream_descriptor.cpp
97.4% Lines (37 / 38)
78.6% Branches (11 / 14)
100.0% Functions (7 / 7)
Functions (7)
Function
Calls
Lines
Branches
Blocks
boost::corosio::posix_stream_descriptor::~posix_stream_descriptor()
:23
398x
100.0%
–
100.0%
boost::corosio::posix_stream_descriptor::posix_stream_descriptor(boost::capy::execution_context&)
:28
191x
100.0%
–
100.0%
boost::corosio::posix_stream_descriptor::assign(int)
:38
197x
100.0%
75.0%
83.0%
boost::corosio::posix_stream_descriptor::release()
:47
8x
100.0%
100.0%
100.0%
boost::corosio::posix_stream_descriptor::close()
:57
213x
100.0%
75.0%
80.0%
boost::corosio::posix_stream_descriptor::native_handle() const
:65
10x
80.0%
50.0%
75.0%
boost::corosio::posix_stream_descriptor::cancel()
:73
46x
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/posix_stream_descriptor.hpp> | |||
| 11 | #include <boost/corosio/error.hpp> | |||
| 12 | ||||
| 13 | #include <boost/corosio/detail/platform.hpp> | |||
| 14 | ||||
| 15 | #if BOOST_COROSIO_POSIX | |||
| 16 | ||||
| 17 | #include <boost/corosio/detail/descriptor_service.hpp> | |||
| 18 | ||||
| 19 | #include "src/detail/use_backend_service.hpp" | |||
| 20 | ||||
| 21 | namespace boost::corosio { | |||
| 22 | ||||
| 23 | 398x | posix_stream_descriptor::~posix_stream_descriptor() | ||
| 24 | 398x | { | ||
| 25 | 205x | close(); | ||
| 26 | 398x | } | ||
| 27 | ||||
| 28 | 382x | posix_stream_descriptor::posix_stream_descriptor(capy::execution_context& ctx) | ||
| 29 | 191x | : io_object(handle( | ||
| 30 | 191x | ctx, | ||
| 31 | 191x | detail::use_backend_service< | ||
| 32 | detail::descriptor_service_of, | |||
| 33 | 191x | detail::descriptor_service>(ctx))) | ||
| 34 | 382x | { | ||
| 35 | 191x | } | ||
| 36 | ||||
| 37 | std::error_code | |||
| 38 | 197x | posix_stream_descriptor::assign(native_handle_type fd) noexcept | ||
| 39 | { | |||
| 40 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 193 times.
|
197x | if (is_open()) | |
| 41 | 4x | return make_error_code(error::already_open); | ||
| 42 | 193x | auto& svc = static_cast<detail::descriptor_service&>(h_.service()); | ||
| 43 |
1/2✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
|
193x | return svc.assign_descriptor(get(), fd); | |
| 44 | 197x | } | ||
| 45 | ||||
| 46 | capy::results<native_handle_type> | |||
| 47 | 8x | posix_stream_descriptor::release() noexcept | ||
| 48 | { | |||
| 49 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
|
8x | if (!is_open()) | |
| 50 | 2x | return { | ||
| 51 | 2x | make_error_code(std::errc::bad_file_descriptor), | ||
| 52 | detail::invalid_native_handle}; | |||
| 53 | 6x | return {std::error_code{}, get().release_descriptor()}; | ||
| 54 | 8x | } | ||
| 55 | ||||
| 56 | void | |||
| 57 | 213x | posix_stream_descriptor::close() noexcept | ||
| 58 | { | |||
| 59 |
2/2✓ Branch 0 taken 168 times.
✓ Branch 1 taken 45 times.
|
213x | if (!is_open()) | |
| 60 | 45x | return; | ||
| 61 |
1/2✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
|
168x | h_.service().close(h_); | |
| 62 | 213x | } | ||
| 63 | ||||
| 64 | native_handle_type | |||
| 65 | 10x | posix_stream_descriptor::native_handle() const noexcept | ||
| 66 | { | |||
| 67 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10x | if (!h_) | |
| 68 | ✗ | return -1; | ||
| 69 | 10x | return get().native_handle(); | ||
| 70 | 10x | } | ||
| 71 | ||||
| 72 | void | |||
| 73 | 46x | posix_stream_descriptor::cancel() noexcept | ||
| 74 | { | |||
| 75 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 44 times.
|
46x | if (!is_open()) | |
| 76 | 2x | return; | ||
| 77 | 44x | get().cancel(); | ||
| 78 | 46x | } | ||
| 79 | ||||
| 80 | } // namespace boost::corosio | |||
| 81 | ||||
| 82 | #endif // BOOST_COROSIO_POSIX | |||
| 83 |