src/corosio/src/local_stream_acceptor.cpp
69.4% Lines (43/62)
66.7% List of functions (6/9)
41.7% Branches (10/24)
Functions (9)
Function
Calls
Lines
Branches
Blocks
boost::corosio::local_stream_acceptor::~local_stream_acceptor()
:23
24x
100.0%
50.0%
100.0%
boost::corosio::local_stream_acceptor::local_stream_acceptor(boost::capy::execution_context&)
:28
24x
100.0%
–
100.0%
boost::corosio::local_stream_acceptor::open(boost::corosio::local_stream)
:35
12x
81.8%
50.0%
60.0%
boost::corosio::local_stream_acceptor::bind(boost::corosio::local_endpoint, boost::corosio::bind_option)
:49
12x
93.3%
62.5%
85.0%
boost::corosio::local_stream_acceptor::listen(int)
:79
4x
87.5%
50.0%
66.0%
boost::corosio::local_stream_acceptor::close()
:91
12x
80.0%
50.0%
75.0%
boost::corosio::local_stream_acceptor::release()
:99
0
0.0%
0.0%
0.0%
boost::corosio::local_stream_acceptor::cancel()
:107
0
0.0%
0.0%
0.0%
boost::corosio::local_stream_acceptor::local_endpoint() const
:115
0
0.0%
0.0%
0.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_stream_acceptor.hpp> | |||
| 11 | #include <boost/corosio/detail/except.hpp> | |||
| 12 | #include <boost/corosio/detail/platform.hpp> | |||
| 13 | #include <boost/corosio/detail/local_stream_acceptor_service.hpp> | |||
| 14 | ||||
| 15 | #include <cstring> | |||
| 16 | ||||
| 17 | #if BOOST_COROSIO_POSIX | |||
| 18 | #include <unistd.h> | |||
| 19 | #endif | |||
| 20 | ||||
| 21 | namespace boost::corosio { | |||
| 22 | ||||
| 23 | 24x | local_stream_acceptor::~local_stream_acceptor() | ||
| 24 | 24x | { | ||
| 25 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12x | close(); | |
| 26 | 24x | } | ||
| 27 | ||||
| 28 | 24x | local_stream_acceptor::local_stream_acceptor(capy::execution_context& ctx) | ||
| 29 | 12x | : io_object(create_handle<detail::local_stream_acceptor_service>(ctx)) | ||
| 30 | 12x | , ctx_(ctx) | ||
| 31 | 24x | { | ||
| 32 | 24x | } | ||
| 33 | ||||
| 34 | void | |||
| 35 | 12x | local_stream_acceptor::open(local_stream proto) | ||
| 36 | { | |||
| 37 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12x | if (is_open()) | |
| 38 | ✗ | return; | ||
| 39 | 12x | auto& svc = | ||
| 40 | 12x | static_cast<detail::local_stream_acceptor_service&>(h_.service()); | ||
| 41 | 24x | auto ec = svc.open_acceptor_socket( | ||
| 42 | 12x | static_cast<local_stream_acceptor::implementation&>(*h_.get()), | ||
| 43 | 12x | proto.family(), proto.type(), proto.protocol()); | ||
| 44 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12x | if (ec) | |
| 45 | ✗ | detail::throw_system_error(ec, "local_stream_acceptor::open"); | ||
| 46 | 12x | } | ||
| 47 | ||||
| 48 | std::error_code | |||
| 49 | 12x | local_stream_acceptor::bind(corosio::local_endpoint ep, bind_option opt) | ||
| 50 | { | |||
| 51 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12x | if (!is_open()) | |
| 52 | ✗ | detail::throw_logic_error("bind: acceptor not open"); | ||
| 53 | ||||
| 54 | #if BOOST_COROSIO_POSIX | |||
| 55 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
16x | if (opt == bind_option::unlink_existing && | |
| 56 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4x | !ep.empty() && !ep.is_abstract()) | |
| 57 | { | |||
| 58 | // Best-effort removal; ENOENT is fine. | |||
| 59 | 4x | auto p = ep.path(); | ||
| 60 | // path() is not null-terminated for the fixed buffer, | |||
| 61 | // so copy to a local array for unlink. | |||
| 62 | char buf[local_endpoint::max_path_length + 1]; | |||
| 63 | 4x | std::memcpy(buf, p.data(), p.size()); | ||
| 64 | 4x | buf[p.size()] = '\0'; | ||
| 65 | 4x | ::unlink(buf); | ||
| 66 | 4x | } | ||
| 67 | #else | |||
| 68 | (void)opt; | |||
| 69 | #endif | |||
| 70 | ||||
| 71 | 12x | auto& svc = | ||
| 72 | 12x | static_cast<detail::local_stream_acceptor_service&>(h_.service()); | ||
| 73 | 24x | return svc.bind_acceptor( | ||
| 74 | 12x | static_cast<local_stream_acceptor::implementation&>(*h_.get()), | ||
| 75 | 12x | ep); | ||
| 76 | } | |||
| 77 | ||||
| 78 | std::error_code | |||
| 79 | 4x | local_stream_acceptor::listen(int backlog) | ||
| 80 | { | |||
| 81 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4x | if (!is_open()) | |
| 82 | ✗ | detail::throw_logic_error("listen: acceptor not open"); | ||
| 83 | 4x | auto& svc = | ||
| 84 | 4x | static_cast<detail::local_stream_acceptor_service&>(h_.service()); | ||
| 85 | 8x | return svc.listen_acceptor( | ||
| 86 | 4x | static_cast<local_stream_acceptor::implementation&>(*h_.get()), | ||
| 87 | 4x | backlog); | ||
| 88 | } | |||
| 89 | ||||
| 90 | void | |||
| 91 | 12x | local_stream_acceptor::close() | ||
| 92 | { | |||
| 93 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12x | if (!is_open()) | |
| 94 | ✗ | return; | ||
| 95 | 12x | h_.service().close(h_); | ||
| 96 | 12x | } | ||
| 97 | ||||
| 98 | native_handle_type | |||
| 99 | ✗ | local_stream_acceptor::release() | ||
| 100 | { | |||
| 101 | ✗ | if (!is_open()) | ||
| 102 | ✗ | detail::throw_logic_error("release: acceptor not open"); | ||
| 103 | ✗ | return get().release_socket(); | ||
| 104 | } | |||
| 105 | ||||
| 106 | void | |||
| 107 | ✗ | local_stream_acceptor::cancel() | ||
| 108 | { | |||
| 109 | ✗ | if (!is_open()) | ||
| 110 | ✗ | return; | ||
| 111 | ✗ | get().cancel(); | ||
| 112 | ✗ | } | ||
| 113 | ||||
| 114 | local_endpoint | |||
| 115 | ✗ | local_stream_acceptor::local_endpoint() const noexcept | ||
| 116 | { | |||
| 117 | ✗ | if (!is_open()) | ||
| 118 | ✗ | return corosio::local_endpoint{}; | ||
| 119 | ✗ | return get().local_endpoint(); | ||
| 120 | ✗ | } | ||
| 121 | ||||
| 122 | } // namespace boost::corosio | |||
| 123 |