src/corosio/src/local_endpoint.cpp

100.0% Lines (24 / 24) 100.0% Branches (8 / 8) 100.0% Functions (3 / 3)
local_endpoint.cpp
f(x) Functions (3)
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 2168x local_endpoint::local_endpoint(from_path_t, std::string_view path) noexcept
19 1084x {
20 // An empty view may carry a null data pointer, which memcpy rejects.
21
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1082 times.
1084x if (!path.empty())
22 1082x std::memcpy(path_, path.data(), path.size());
23 1084x len_ = static_cast<std::uint8_t>(path.size());
24 1084x }
25
26 capy::results<local_endpoint>
27 1087x make_local_endpoint(std::string_view path) noexcept
28 {
29
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1084 times.
1087x if (path.size() > local_endpoint::max_path_length)
30 {
31 3x return {
32 3x std::make_error_code(std::errc::filename_too_long),
33 3x local_endpoint{}};
34 }
35 1084x return {
36 1084x std::error_code{}, local_endpoint(local_endpoint::from_path_t{}, path)};
37 1087x }
38
39 std::ostream&
40 6x operator<<(std::ostream& os, local_endpoint const& ep)
41 {
42
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6x if (ep.empty())
43 2x return os;
44
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4x if (ep.is_abstract())
45 {
46 // Skip the leading null byte; print the rest as the name
47 2x os << "[abstract:" << std::string_view(ep.path_ + 1, ep.len_ - 1)
48 2x << ']';
49 2x }
50 else
51 {
52 2x os << ep.path();
53 }
54 4x return os;
55 6x }
56
57 } // namespace boost::corosio
58