src/corosio/src/local_endpoint.cpp
91.3% Lines (21/23)
100.0% List of functions (3/3)
Functions (3)
Function
Calls
Lines
Blocks
boost::corosio::local_endpoint::local_endpoint(std::basic_string_view<char, std::char_traits<char> >)
:19
50x
71.4%
78.0%
boost::corosio::local_endpoint::local_endpoint(std::basic_string_view<char, std::char_traits<char> >, std::error_code&)
:29
36x
100.0%
100.0%
boost::corosio::operator<<(std::ostream&, boost::corosio::local_endpoint const&)
:43
6x
100.0%
100.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/local_endpoint.hpp> | ||
| 11 | #include <boost/corosio/detail/except.hpp> | ||
| 12 | |||
| 13 | #include <cstring> | ||
| 14 | #include <ostream> | ||
| 15 | #include <system_error> | ||
| 16 | |||
| 17 | namespace boost::corosio { | ||
| 18 | |||
| 19 | 50x | local_endpoint::local_endpoint(std::string_view path) | |
| 20 | { | ||
| 21 | 50x | if (path.size() > max_path_length) | |
| 22 | ✗ | detail::throw_system_error( | |
| 23 | ✗ | std::make_error_code(std::errc::filename_too_long), | |
| 24 | "local_endpoint"); | ||
| 25 | 50x | std::memcpy(path_, path.data(), path.size()); | |
| 26 | 50x | len_ = static_cast<std::uint8_t>(path.size()); | |
| 27 | 50x | } | |
| 28 | |||
| 29 | 36x | local_endpoint::local_endpoint( | |
| 30 | 36x | std::string_view path, std::error_code& ec) noexcept | |
| 31 | { | ||
| 32 | 36x | if (path.size() > max_path_length) | |
| 33 | { | ||
| 34 | 4x | ec = std::make_error_code(std::errc::filename_too_long); | |
| 35 | 4x | return; | |
| 36 | } | ||
| 37 | 32x | ec = {}; | |
| 38 | 32x | std::memcpy(path_, path.data(), path.size()); | |
| 39 | 32x | len_ = static_cast<std::uint8_t>(path.size()); | |
| 40 | } | ||
| 41 | |||
| 42 | std::ostream& | ||
| 43 | 6x | operator<<(std::ostream& os, local_endpoint const& ep) | |
| 44 | { | ||
| 45 | 6x | if (ep.empty()) | |
| 46 | 2x | return os; | |
| 47 | 4x | if (ep.is_abstract()) | |
| 48 | { | ||
| 49 | // Skip the leading null byte; print the rest as the name | ||
| 50 | os << "[abstract:" | ||
| 51 | 2x | << std::string_view(ep.path_ + 1, ep.len_ - 1) | |
| 52 | 2x | << ']'; | |
| 53 | } | ||
| 54 | else | ||
| 55 | { | ||
| 56 | 2x | os << ep.path(); | |
| 57 | } | ||
| 58 | 4x | return os; | |
| 59 | } | ||
| 60 | |||
| 61 | } // namespace boost::corosio | ||
| 62 |