include/boost/corosio/native/detail/select/select_acceptor.hpp
100.0% Lines (9/9)
100.0% Functions (4/4)
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2026 Steve Gerbino | ||
| 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 | #ifndef BOOST_COROSIO_NATIVE_DETAIL_SELECT_SELECT_ACCEPTOR_HPP | ||
| 11 | #define BOOST_COROSIO_NATIVE_DETAIL_SELECT_SELECT_ACCEPTOR_HPP | ||
| 12 | |||
| 13 | #include <boost/corosio/detail/platform.hpp> | ||
| 14 | |||
| 15 | #if BOOST_COROSIO_HAS_SELECT | ||
| 16 | |||
| 17 | #include <boost/corosio/tcp_acceptor.hpp> | ||
| 18 | #include <boost/capy/ex/executor_ref.hpp> | ||
| 19 | #include <boost/corosio/detail/intrusive.hpp> | ||
| 20 | |||
| 21 | #include <boost/corosio/native/detail/select/select_op.hpp> | ||
| 22 | |||
| 23 | #include <memory> | ||
| 24 | |||
| 25 | namespace boost::corosio::detail { | ||
| 26 | |||
| 27 | class select_acceptor_service; | ||
| 28 | class select_socket_service; | ||
| 29 | |||
| 30 | /// Acceptor implementation for select backend. | ||
| 31 | class select_acceptor final | ||
| 32 | : public tcp_acceptor::implementation | ||
| 33 | , public std::enable_shared_from_this<select_acceptor> | ||
| 34 | , public intrusive_list<select_acceptor>::node | ||
| 35 | { | ||
| 36 | friend class select_acceptor_service; | ||
| 37 | |||
| 38 | public: | ||
| 39 | explicit select_acceptor(select_acceptor_service& svc) noexcept; | ||
| 40 | |||
| 41 | std::coroutine_handle<> accept( | ||
| 42 | std::coroutine_handle<>, | ||
| 43 | capy::executor_ref, | ||
| 44 | std::stop_token, | ||
| 45 | std::error_code*, | ||
| 46 | io_object::implementation**) override; | ||
| 47 | |||
| 48 | int native_handle() const noexcept | ||
| 49 | { | ||
| 50 | return fd_; | ||
| 51 | } | ||
| 52 | 41 | endpoint local_endpoint() const noexcept override | |
| 53 | { | ||
| 54 | 41 | return local_endpoint_; | |
| 55 | } | ||
| 56 | 3713 | bool is_open() const noexcept override | |
| 57 | { | ||
| 58 | 3713 | return fd_ >= 0; | |
| 59 | } | ||
| 60 | void cancel() noexcept override; | ||
| 61 | void cancel_single_op(select_op& op) noexcept; | ||
| 62 | void close_socket() noexcept; | ||
| 63 | 44 | void set_local_endpoint(endpoint ep) noexcept | |
| 64 | { | ||
| 65 | 44 | local_endpoint_ = ep; | |
| 66 | 44 | } | |
| 67 | |||
| 68 | 3526 | select_acceptor_service& service() noexcept | |
| 69 | { | ||
| 70 | 3526 | return svc_; | |
| 71 | } | ||
| 72 | |||
| 73 | select_accept_op acc_; | ||
| 74 | |||
| 75 | private: | ||
| 76 | select_acceptor_service& svc_; | ||
| 77 | int fd_ = -1; | ||
| 78 | endpoint local_endpoint_; | ||
| 79 | }; | ||
| 80 | |||
| 81 | } // namespace boost::corosio::detail | ||
| 82 | |||
| 83 | #endif // BOOST_COROSIO_HAS_SELECT | ||
| 84 | |||
| 85 | #endif // BOOST_COROSIO_NATIVE_DETAIL_SELECT_SELECT_ACCEPTOR_HPP | ||
| 86 |