src/corosio/src/local_endpoint.cpp

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