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