src/corosio/src/tcp_acceptor.cpp
91.7% Lines (22/24)
100.0% Functions (6/6)
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 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 | 115 | tcp_acceptor::~tcp_acceptor() | |
| 25 | { | ||
| 26 | 115 | close(); | |
| 27 | 115 | } | |
| 28 | |||
| 29 | 109 | tcp_acceptor::tcp_acceptor(capy::execution_context& ctx) | |
| 30 | #if BOOST_COROSIO_HAS_IOCP | ||
| 31 | : io_object(create_handle<detail::win_acceptor_service>(ctx)) | ||
| 32 | #else | ||
| 33 | 109 | : io_object(create_handle<detail::acceptor_service>(ctx)) | |
| 34 | #endif | ||
| 35 | { | ||
| 36 | 109 | } | |
| 37 | |||
| 38 | std::error_code | ||
| 39 | 110 | tcp_acceptor::listen(endpoint ep, int backlog) | |
| 40 | { | ||
| 41 | 110 | if (is_open()) | |
| 42 | 1 | close(); | |
| 43 | |||
| 44 | #if BOOST_COROSIO_HAS_IOCP | ||
| 45 | auto& svc = static_cast<detail::win_acceptor_service&>(h_.service()); | ||
| 46 | #else | ||
| 47 | 110 | auto& svc = static_cast<detail::acceptor_service&>(h_.service()); | |
| 48 | #endif | ||
| 49 | 110 | return svc.open_acceptor( | |
| 50 | 220 | *static_cast<tcp_acceptor::implementation*>(h_.get()), ep, backlog); | |
| 51 | } | ||
| 52 | |||
| 53 | void | ||
| 54 | 214 | tcp_acceptor::close() | |
| 55 | { | ||
| 56 | 214 | if (!is_open()) | |
| 57 | 106 | return; | |
| 58 | 108 | h_.service().close(h_); | |
| 59 | } | ||
| 60 | |||
| 61 | void | ||
| 62 | 2 | tcp_acceptor::cancel() | |
| 63 | { | ||
| 64 | 2 | if (!is_open()) | |
| 65 | ✗ | return; | |
| 66 | 2 | get().cancel(); | |
| 67 | } | ||
| 68 | |||
| 69 | endpoint | ||
| 70 | 90 | tcp_acceptor::local_endpoint() const noexcept | |
| 71 | { | ||
| 72 | 90 | if (!is_open()) | |
| 73 | ✗ | return endpoint{}; | |
| 74 | 90 | return get().local_endpoint(); | |
| 75 | } | ||
| 76 | |||
| 77 | } // namespace boost::corosio | ||
| 78 |