src/corosio/src/local_endpoint.cpp
100.0% Lines (18 / 18)
100.0% Branches (10 / 10)
100.0% Functions (3 / 3)
Functions (3)
Function
Calls
Lines
Branches
Blocks
boost::corosio::local_endpoint::local_endpoint(boost::corosio::local_endpoint::from_path_t, std::basic_string_view<char, std::char_traits<char> >)
:18
170x
100.0%
100.0%
100.0%
boost::corosio::make_local_endpoint(std::basic_string_view<char, std::char_traits<char> >)
:27
267x
100.0%
100.0%
100.0%
boost::corosio::operator<<(std::ostream&, boost::corosio::local_endpoint const&)
:40
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/local_endpoint.hpp> | |||
| 11 | ||||
| 12 | #include <cstring> | |||
| 13 | #include <ostream> | |||
| 14 | #include <system_error> | |||
| 15 | ||||
| 16 | namespace boost::corosio { | |||
| 17 | ||||
| 18 | 170x | local_endpoint::local_endpoint(from_path_t, std::string_view path) noexcept | ||
| 19 | { | |||
| 20 | // An empty view may carry a null data pointer, which memcpy rejects. | |||
| 21 |
2/2✓ Branch 3 → 4 taken 168 times.
✓ Branch 3 → 7 taken 2 times.
|
170x | if (!path.empty()) | |
| 22 | 168x | std::memcpy(path_, path.data(), path.size()); | ||
| 23 | 170x | len_ = static_cast<std::uint8_t>(path.size()); | ||
| 24 | 170x | } | ||
| 25 | ||||
| 26 | capy::results<local_endpoint> | |||
| 27 | 267x | make_local_endpoint(std::string_view path) noexcept | ||
| 28 | { | |||
| 29 |
2/2✓ Branch 3 → 4 taken 97 times.
✓ Branch 3 → 8 taken 170 times.
|
267x | if (path.size() > local_endpoint::max_path_length) | |
| 30 | { | |||
| 31 | return { | |||
| 32 | 97x | std::make_error_code(std::errc::filename_too_long), | ||
| 33 | 97x | local_endpoint{}}; | ||
| 34 | } | |||
| 35 | return { | |||
| 36 | 170x | std::error_code{}, local_endpoint(local_endpoint::from_path_t{}, path)}; | ||
| 37 | } | |||
| 38 | ||||
| 39 | std::ostream& | |||
| 40 | 3x | operator<<(std::ostream& os, local_endpoint const& ep) | ||
| 41 | { | |||
| 42 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 2 times.
|
3x | if (ep.empty()) | |
| 43 | 1x | return os; | ||
| 44 |
2/2✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 12 taken 1 time.
|
2x | if (ep.is_abstract()) | |
| 45 | { | |||
| 46 | // Skip the leading null byte; print the rest as the name | |||
| 47 | 1x | os << "[abstract:" << std::string_view(ep.path_ + 1, ep.len_ - 1) | ||
| 48 |
2/2✓ Branch 9 → 10 taken 1 time.
✓ Branch 10 → 11 taken 1 time.
|
1x | << ']'; | |
| 49 | } | |||
| 50 | else | |||
| 51 | { | |||
| 52 | 1x | os << ep.path(); | ||
| 53 | } | |||
| 54 | 2x | return os; | ||
| 55 | } | |||
| 56 | ||||
| 57 | } // namespace boost::corosio | |||
| 58 |