src/corosio/src/posix_descriptor.cpp
85.2% Lines (23 / 27)
100.0% Functions (7 / 7)
Functions (7)
Function
Calls
Lines
Blocks
boost::corosio::posix_descriptor::~posix_descriptor()
:23
59x
100.0%
100.0%
boost::corosio::posix_descriptor::posix_descriptor(boost::capy::execution_context&)
:28
47x
100.0%
100.0%
boost::corosio::posix_descriptor::assign(int)
:38
55x
100.0%
100.0%
boost::corosio::posix_descriptor::release()
:45
2x
60.0%
75.0%
boost::corosio::posix_descriptor::close()
:55
59x
100.0%
100.0%
boost::corosio::posix_descriptor::native_handle() const
:63
10x
75.0%
83.0%
boost::corosio::posix_descriptor::cancel()
:71
3x
75.0%
83.0%
| Line | 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_descriptor.hpp> | ||
| 11 | |||
| 12 | #include <boost/corosio/detail/platform.hpp> | ||
| 13 | |||
| 14 | #if BOOST_COROSIO_POSIX | ||
| 15 | |||
| 16 | #include <boost/corosio/detail/descriptor_service.hpp> | ||
| 17 | #include <boost/corosio/detail/except.hpp> | ||
| 18 | |||
| 19 | #include "src/detail/use_backend_service.hpp" | ||
| 20 | |||
| 21 | namespace boost::corosio { | ||
| 22 | |||
| 23 | 59x | posix_descriptor::~posix_descriptor() | |
| 24 | { | ||
| 25 | 59x | close(); | |
| 26 | 59x | } | |
| 27 | |||
| 28 | 47x | posix_descriptor::posix_descriptor(capy::execution_context& ctx) | |
| 29 | 47x | : io_object(handle( | |
| 30 | ctx, | ||
| 31 | detail::use_backend_service< | ||
| 32 | detail::descriptor_service_of, | ||
| 33 | 94x | detail::descriptor_service>(ctx))) | |
| 34 | { | ||
| 35 | 47x | } | |
| 36 | |||
| 37 | std::error_code | ||
| 38 | 55x | posix_descriptor::assign(native_handle_type fd) noexcept | |
| 39 | { | ||
| 40 | 55x | auto& svc = static_cast<detail::descriptor_service&>(h_.service()); | |
| 41 | 55x | return svc.assign_descriptor(get(), fd); | |
| 42 | } | ||
| 43 | |||
| 44 | native_handle_type | ||
| 45 | 2x | posix_descriptor::release() | |
| 46 | { | ||
| 47 | 2x | if (!is_open()) | |
| 48 | ✗ | detail::throw_system_error( | |
| 49 | ✗ | make_error_code(std::errc::bad_file_descriptor), | |
| 50 | "posix_descriptor::release"); | ||
| 51 | 2x | return get().release_descriptor(); | |
| 52 | } | ||
| 53 | |||
| 54 | void | ||
| 55 | 59x | posix_descriptor::close() noexcept | |
| 56 | { | ||
| 57 | 59x | if (!is_open()) | |
| 58 | 16x | return; | |
| 59 | 43x | h_.service().close(h_); | |
| 60 | } | ||
| 61 | |||
| 62 | native_handle_type | ||
| 63 | 10x | posix_descriptor::native_handle() const noexcept | |
| 64 | { | ||
| 65 | 10x | if (!h_) | |
| 66 | ✗ | return -1; | |
| 67 | 10x | return get().native_handle(); | |
| 68 | } | ||
| 69 | |||
| 70 | void | ||
| 71 | 3x | posix_descriptor::cancel() noexcept | |
| 72 | { | ||
| 73 | 3x | if (!is_open()) | |
| 74 | ✗ | return; | |
| 75 | 3x | get().cancel(); | |
| 76 | } | ||
| 77 | |||
| 78 | } // namespace boost::corosio | ||
| 79 | |||
| 80 | #endif // BOOST_COROSIO_POSIX | ||
| 81 |