src/corosio/src/tcp_acceptor.cpp

91.7% Lines (22/24) 100.0% Functions (6/6) 77.8% Branches (7/9)
src/corosio/src/tcp_acceptor.cpp
Line Branch TLA Hits Source Code
1 //
2 // Copyright (c) 2025 Vinnie Falco ([email protected])
3 // Copyright (c) 2026 Steve Gerbino
4 //
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // Official repository: https://github.com/cppalliance/corosio
9 //
10
11 #include <boost/corosio/tcp_acceptor.hpp>
12 #include <boost/corosio/detail/platform.hpp>
13
14 #if BOOST_COROSIO_HAS_IOCP
15 #include <boost/corosio/native/detail/iocp/win_acceptor_service.hpp>
16 #else
17 #include <boost/corosio/detail/acceptor_service.hpp>
18 #endif
19
20 #include <boost/corosio/detail/except.hpp>
21
22 namespace boost::corosio {
23
24 1160 tcp_acceptor::~tcp_acceptor()
25 {
26 1160 close();
27 1160 }
28
29 1150 tcp_acceptor::tcp_acceptor(capy::execution_context& ctx)
30 #if BOOST_COROSIO_HAS_IOCP
31
1/1
✓ Branch 2 → 3 taken 1150 times.
1150 : io_object(create_handle<detail::win_acceptor_service>(ctx))
32 #else
33 : io_object(create_handle<detail::acceptor_service>(ctx))
34 #endif
35 {
36 1150 }
37
38 std::error_code
39 1156 tcp_acceptor::listen(endpoint ep, int backlog)
40 {
41
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 1155 times.
1156 if (is_open())
42 1 close();
43
44 #if BOOST_COROSIO_HAS_IOCP
45 1156 auto& svc = static_cast<detail::win_acceptor_service&>(h_.service());
46 #else
47 auto& svc = static_cast<detail::acceptor_service&>(h_.service());
48 #endif
49 1156 return svc.open_acceptor(
50 2312 *static_cast<tcp_acceptor::implementation*>(h_.get()), ep, backlog);
51 }
52
53 void
54 2301 tcp_acceptor::close()
55 {
56
2/2
✓ Branch 3 → 4 taken 1147 times.
✓ Branch 3 → 5 taken 1154 times.
2301 if (!is_open())
57 1147 return;
58 1154 h_.service().close(h_);
59 }
60
61 void
62 1 tcp_acceptor::cancel()
63 {
64
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 1 time.
1 if (!is_open())
65 return;
66 1 get().cancel();
67 }
68
69 endpoint
70 1137 tcp_acceptor::local_endpoint() const noexcept
71 {
72
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 1137 times.
1137 if (!is_open())
73 return endpoint{};
74 1137 return get().local_endpoint();
75 }
76
77 } // namespace boost::corosio
78