100.00% Lines (51/51)
100.00% Functions (14/14)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2026 Steve Gerbino | 2 | // Copyright (c) 2026 Steve Gerbino | |||||
| 3 | // | 3 | // | |||||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 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) | 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 6 | // | 6 | // | |||||
| 7 | // Official repository: https://github.com/cppalliance/corosio | 7 | // Official repository: https://github.com/cppalliance/corosio | |||||
| 8 | // | 8 | // | |||||
| 9 | 9 | |||||||
| 10 | #ifndef BOOST_COROSIO_NATIVE_NATIVE_LOCAL_STREAM_ACCEPTOR_HPP | 10 | #ifndef BOOST_COROSIO_NATIVE_NATIVE_LOCAL_STREAM_ACCEPTOR_HPP | |||||
| 11 | #define BOOST_COROSIO_NATIVE_NATIVE_LOCAL_STREAM_ACCEPTOR_HPP | 11 | #define BOOST_COROSIO_NATIVE_NATIVE_LOCAL_STREAM_ACCEPTOR_HPP | |||||
| 12 | 12 | |||||||
| 13 | #include <boost/corosio/local_stream_acceptor.hpp> | 13 | #include <boost/corosio/local_stream_acceptor.hpp> | |||||
| 14 | #include <boost/corosio/native/native_local_stream_socket.hpp> | 14 | #include <boost/corosio/native/native_local_stream_socket.hpp> | |||||
| 15 | #include <boost/corosio/backend.hpp> | 15 | #include <boost/corosio/backend.hpp> | |||||
| 16 | + | #include <boost/corosio/detail/op_base.hpp> | ||||||
| 16 | 17 | |||||||
| 17 | #ifndef BOOST_COROSIO_MRDOCS | 18 | #ifndef BOOST_COROSIO_MRDOCS | |||||
| 18 | #if BOOST_COROSIO_HAS_EPOLL | 19 | #if BOOST_COROSIO_HAS_EPOLL | |||||
| 19 | #include <boost/corosio/native/detail/epoll/epoll_types.hpp> | 20 | #include <boost/corosio/native/detail/epoll/epoll_types.hpp> | |||||
| 20 | #endif | 21 | #endif | |||||
| 21 | 22 | |||||||
| 22 | #if BOOST_COROSIO_HAS_SELECT | 23 | #if BOOST_COROSIO_HAS_SELECT | |||||
| 23 | #include <boost/corosio/native/detail/select/select_types.hpp> | 24 | #include <boost/corosio/native/detail/select/select_types.hpp> | |||||
| 24 | #endif | 25 | #endif | |||||
| 25 | 26 | |||||||
| 26 | #if BOOST_COROSIO_HAS_KQUEUE | 27 | #if BOOST_COROSIO_HAS_KQUEUE | |||||
| 27 | #include <boost/corosio/native/detail/kqueue/kqueue_types.hpp> | 28 | #include <boost/corosio/native/detail/kqueue/kqueue_types.hpp> | |||||
| 28 | #endif | 29 | #endif | |||||
| 29 | 30 | |||||||
| 30 | #if BOOST_COROSIO_HAS_URING | 31 | #if BOOST_COROSIO_HAS_URING | |||||
| 31 | #include <boost/corosio/native/detail/uring/uring_types.hpp> | 32 | #include <boost/corosio/native/detail/uring/uring_types.hpp> | |||||
| 32 | #endif | 33 | #endif | |||||
| 33 | 34 | |||||||
| 34 | #if BOOST_COROSIO_HAS_IOCP | 35 | #if BOOST_COROSIO_HAS_IOCP | |||||
| 35 | #include <boost/corosio/native/detail/iocp/win_local_stream_acceptor_service.hpp> | 36 | #include <boost/corosio/native/detail/iocp/win_local_stream_acceptor_service.hpp> | |||||
| 36 | #endif | 37 | #endif | |||||
| 37 | #endif // !BOOST_COROSIO_MRDOCS | 38 | #endif // !BOOST_COROSIO_MRDOCS | |||||
| 38 | 39 | |||||||
| 39 | namespace boost::corosio { | 40 | namespace boost::corosio { | |||||
| 40 | 41 | |||||||
| 41 | /** An asynchronous Unix stream acceptor with devirtualized accept. | 42 | /** An asynchronous Unix stream acceptor with devirtualized accept. | |||||
| 42 | 43 | |||||||
| 43 | This class template inherits from @ref local_stream_acceptor | 44 | This class template inherits from @ref local_stream_acceptor | |||||
| 44 | and shadows both `accept` overloads (the peer-reference form | 45 | and shadows both `accept` overloads (the peer-reference form | |||||
| 45 | and the move-return form) with versions that call the backend | 46 | and the move-return form) with versions that call the backend | |||||
| 46 | implementation directly, allowing the compiler to inline | 47 | implementation directly, allowing the compiler to inline | |||||
| 47 | through the entire call chain. The move-return form yields a | 48 | through the entire call chain. The move-return form yields a | |||||
| 48 | @ref native_local_stream_socket so subsequent I/O on the peer | 49 | @ref native_local_stream_socket so subsequent I/O on the peer | |||||
| 49 | is also devirtualized. | 50 | is also devirtualized. | |||||
| 50 | 51 | |||||||
| 51 | Non-async operations (`listen`, `close`, `cancel`) remain | 52 | Non-async operations (`listen`, `close`, `cancel`) remain | |||||
| 52 | unchanged and dispatch through the compiled library. | 53 | unchanged and dispatch through the compiled library. | |||||
| 53 | 54 | |||||||
| 54 | A `native_local_stream_acceptor` IS-A `local_stream_acceptor` | 55 | A `native_local_stream_acceptor` IS-A `local_stream_acceptor` | |||||
| 55 | and can be passed to any function expecting | 56 | and can be passed to any function expecting | |||||
| 56 | `local_stream_acceptor&`. | 57 | `local_stream_acceptor&`. | |||||
| 57 | 58 | |||||||
| 58 | @tparam Backend A backend tag value (e.g., `epoll`). | 59 | @tparam Backend A backend tag value (e.g., `epoll`). | |||||
| 59 | 60 | |||||||
| 60 | @par Thread Safety | 61 | @par Thread Safety | |||||
| 61 | Same as @ref local_stream_acceptor. | 62 | Same as @ref local_stream_acceptor. | |||||
| 62 | 63 | |||||||
| 63 | @see local_stream_acceptor, epoll_t, iocp_t | 64 | @see local_stream_acceptor, epoll_t, iocp_t | |||||
| 64 | */ | 65 | */ | |||||
| 65 | template<auto Backend> | 66 | template<auto Backend> | |||||
| 66 | class native_local_stream_acceptor : public local_stream_acceptor | 67 | class native_local_stream_acceptor : public local_stream_acceptor | |||||
| 67 | { | 68 | { | |||||
| 68 | using backend_type = decltype(Backend); | 69 | using backend_type = decltype(Backend); | |||||
| 69 | using impl_type = typename backend_type::local_stream_acceptor_type; | 70 | using impl_type = typename backend_type::local_stream_acceptor_type; | |||||
| 70 | using service_type = | 71 | using service_type = | |||||
| 71 | typename backend_type::local_stream_acceptor_service_type; | 72 | typename backend_type::local_stream_acceptor_service_type; | |||||
| 72 | 73 | |||||||
| HITCBC | 73 | 16 | impl_type& get_impl() noexcept | 74 | 10 | impl_type& get_impl() noexcept | ||
| 74 | { | 75 | { | |||||
| HITCBC | 75 | 16 | return *static_cast<impl_type*>(h_.get()); | 76 | 10 | return *static_cast<impl_type*>(h_.get()); | ||
| 76 | } | 77 | } | |||||
| 77 | 78 | |||||||
| 78 | - | struct native_wait_awaitable | 79 | + | struct native_wait_awaitable : detail::void_op_base<native_wait_awaitable> | |||
| 79 | { | 80 | { | |||||
| 80 | native_local_stream_acceptor& acc_; | 81 | native_local_stream_acceptor& acc_; | |||||
| 81 | - | std::stop_token token_; | ||||||
| 82 | - | mutable std::error_code ec_; | ||||||
| 83 | wait_type w_; | 82 | wait_type w_; | |||||
| 84 | 83 | |||||||
| HITCBC | 85 | 6 | native_wait_awaitable( | 84 | 6 | native_wait_awaitable( | ||
| 86 | native_local_stream_acceptor& acc, wait_type w) noexcept | 85 | native_local_stream_acceptor& acc, wait_type w) noexcept | |||||
| HITCBC | 87 | 6 | : acc_(acc) | 86 | 6 | : acc_(acc) | ||
| HITCBC | 88 | 6 | , w_(w) | 87 | 6 | , w_(w) | ||
| 89 | { | 88 | { | |||||
| HITCBC | 90 | 6 | } | 89 | 6 | } | ||
| 91 | 90 | |||||||
| ECB | 92 | - | 6 | bool await_ready() const noexcept | 91 | + | std::coroutine_handle<> | |
| HITGIC | 93 | - | { | 92 | + | 4 | dispatch(std::coroutine_handle<> h, capy::executor_ref ex) const | |
| 94 | - | // A pre-set ec_ means the initiator failed before | ||||||
| 95 | - | // dispatch (e.g. a closed object). | ||||||
| DCB | 96 | - | 6 | return static_cast<bool>(ec_) || token_.stop_requested(); | ||||
| 97 | - | } | ||||||
| 98 | - | |||||||
| DCB | 99 | - | 6 | [[nodiscard]] capy::io_result<> await_resume() const noexcept | ||||
| 100 | - | { | ||||||
| DCB | 101 | - | 6 | if (token_.stop_requested()) | ||||
| DCB | 102 | - | 2 | return {make_error_code(std::errc::operation_canceled)}; | ||||
| DCB | 103 | - | 4 | return {ec_}; | ||||
| 104 | - | } | ||||||
| 105 | - | |||||||
| DCB | 106 | - | 6 | auto await_suspend(std::coroutine_handle<> h, capy::io_env const* env) | ||||
| 107 | - | -> std::coroutine_handle<> | ||||||
| 108 | { | 93 | { | |||||
| HITCBC | 109 | - | 6 | token_ = env->stop_token; | 94 | + | 4 | return acc_.get_impl().wait(h, ex, w_, this->token_, &this->ec_); |
| DCB | 110 | - | 6 | return acc_.get_impl().wait(h, env->executor, w_, token_, &ec_); | ||||
| 111 | } | 95 | } | |||||
| 112 | }; | 96 | }; | |||||
| 113 | 97 | |||||||
| 114 | struct native_accept_awaitable | 98 | struct native_accept_awaitable | |||||
| 99 | + | : detail::void_op_base<native_accept_awaitable> | ||||||
| 115 | { | 100 | { | |||||
| 116 | native_local_stream_acceptor& acc_; | 101 | native_local_stream_acceptor& acc_; | |||||
| 117 | - | std::stop_token token_; | ||||||
| 118 | - | mutable std::error_code ec_; | ||||||
| 119 | local_stream_socket& peer_; | 102 | local_stream_socket& peer_; | |||||
| 120 | mutable io_object::implementation* peer_impl_ = nullptr; | 103 | mutable io_object::implementation* peer_impl_ = nullptr; | |||||
| 121 | 104 | |||||||
| HITCBC | 122 | 8 | native_accept_awaitable( | 105 | 8 | native_accept_awaitable( | ||
| 123 | native_local_stream_acceptor& acc, | 106 | native_local_stream_acceptor& acc, | |||||
| 124 | local_stream_socket& peer) noexcept | 107 | local_stream_socket& peer) noexcept | |||||
| HITCBC | 125 | 8 | : acc_(acc) | 108 | 8 | : acc_(acc) | ||
| HITCBC | 126 | 8 | , peer_(peer) | 109 | 8 | , peer_(peer) | ||
| 127 | { | 110 | { | |||||
| HITCBC | 128 | 8 | } | 111 | 8 | } | ||
| 129 | - | bool await_ready() const noexcept | ||||||
| DCB | 130 | - | 8 | { | ||||
| 131 | - | // A pre-set ec_ means the initiator failed before | ||||||
| 132 | - | // dispatch (e.g. a closed object). | ||||||
| 133 | - | return static_cast<bool>(ec_) || token_.stop_requested(); | ||||||
| DCB | 134 | - | 8 | } | ||||
| 135 | - | |||||||
| 136 | 112 | |||||||
| HITCBC | 137 | 8 | [[nodiscard]] capy::io_result<> await_resume() const noexcept | 113 | 8 | [[nodiscard]] capy::io_result<> await_resume() const noexcept | ||
| 138 | { | 114 | { | |||||
| HITCBC | 139 | - | 8 | if (token_.stop_requested()) | 115 | + | 8 | if (!this->ec_) |
| DCB | 140 | - | 2 | return {make_error_code(std::errc::operation_canceled)}; | ||||
| DCB | 141 | - | 6 | if (!ec_) | ||||
| HITCBC | 142 | 4 | acc_.reset_peer_impl(peer_, peer_impl_); | 116 | 4 | acc_.reset_peer_impl(peer_, peer_impl_); | ||
| HITCBC | 143 | - | 6 | return {ec_}; | 117 | + | 8 | return {this->ec_}; |
| 144 | } | 118 | } | |||||
| 145 | 119 | |||||||
| ECB | 146 | - | 6 | auto await_suspend(std::coroutine_handle<> h, capy::io_env const* env) | 120 | + | std::coroutine_handle<> | |
| HITGIC | 147 | - | -> std::coroutine_handle<> | 121 | + | 4 | dispatch(std::coroutine_handle<> h, capy::executor_ref ex) const | |
| 148 | - | token_ = env->stop_token; | ||||||
| ECB | 149 | 6 | { | 122 | { | |||
| HITCBC | 150 | 18 | return acc_.get_impl().accept( | 123 | 12 | return acc_.get_impl().accept( | ||
| HITCBC | 151 | - | 18 | h, env->executor, token_, &ec_, &peer_impl_); | 124 | + | 12 | h, ex, this->token_, &this->ec_, &peer_impl_); |
| 152 | } | 125 | } | |||||
| 153 | }; | 126 | }; | |||||
| 154 | 127 | |||||||
| 155 | struct native_move_accept_awaitable | 128 | struct native_move_accept_awaitable | |||||
| 129 | + | : detail::void_op_base<native_move_accept_awaitable> | ||||||
| 156 | { | 130 | { | |||||
| 157 | - | std::stop_token token_; | ||||||
| 158 | - | mutable std::error_code ec_; | ||||||
| 159 | native_local_stream_acceptor& acc_; | 131 | native_local_stream_acceptor& acc_; | |||||
| 160 | mutable io_object::implementation* peer_impl_ = nullptr; | 132 | mutable io_object::implementation* peer_impl_ = nullptr; | |||||
| 161 | 133 | |||||||
| HITCBC | 162 | 6 | explicit native_move_accept_awaitable( | 134 | 6 | explicit native_move_accept_awaitable( | ||
| 163 | native_local_stream_acceptor& acc) noexcept | 135 | native_local_stream_acceptor& acc) noexcept | |||||
| HITCBC | 164 | 6 | : acc_(acc) | 136 | 6 | : acc_(acc) | ||
| 165 | { | 137 | { | |||||
| HITCBC | 166 | 6 | } | 138 | 6 | } | ||
| 167 | - | bool await_ready() const noexcept | ||||||
| DCB | 168 | - | 6 | { | ||||
| 169 | - | // A pre-set ec_ means the initiator failed before | ||||||
| 170 | - | // dispatch (e.g. a closed object). | ||||||
| 171 | - | return static_cast<bool>(ec_) || token_.stop_requested(); | ||||||
| DCB | 172 | - | 6 | } | ||||
| 173 | - | |||||||
| 174 | 139 | |||||||
| 175 | [[nodiscard]] capy::io_result<native_local_stream_socket<Backend>> | 140 | [[nodiscard]] capy::io_result<native_local_stream_socket<Backend>> | |||||
| HITCBC | 176 | 6 | await_resume() const noexcept | 141 | 6 | await_resume() const noexcept | ||
| 177 | { | 142 | { | |||||
| HITCBC | 178 | - | 6 | if (token_.stop_requested()) | 143 | + | 6 | if (this->ec_ || !peer_impl_) |
| 179 | return { | 144 | return { | |||||
| HITCBC | 180 | - | 2 | make_error_code(std::errc::operation_canceled), | 145 | + | 4 | this->ec_, |
| DCB | 181 | - | 2 | if (ec_ || !peer_impl_) | ||||
| DCB | 182 | - | 4 | return { | ||||
| 183 | - | ec_, native_local_stream_socket<Backend>(acc_.context())}; | ||||||
| HITCBC | 184 | 2 | native_local_stream_socket<Backend>(acc_.context())}; | 146 | 4 | native_local_stream_socket<Backend>(acc_.context())}; | ||
| 185 | 147 | |||||||
| HITCBC | 186 | 2 | native_local_stream_socket<Backend> peer(acc_.context()); | 148 | 2 | native_local_stream_socket<Backend> peer(acc_.context()); | ||
| HITCBC | 187 | 2 | acc_.reset_peer_impl(peer, peer_impl_); | 149 | 2 | acc_.reset_peer_impl(peer, peer_impl_); | ||
| HITCBC | 188 | - | 2 | return {ec_, std::move(peer)}; | 150 | + | 2 | return {this->ec_, std::move(peer)}; |
| HITCBC | 189 | 2 | } | 151 | 2 | } | ||
| 190 | 152 | |||||||
| ECB | 191 | - | 4 | auto await_suspend(std::coroutine_handle<> h, capy::io_env const* env) | 153 | + | std::coroutine_handle<> | |
| HITGIC | 192 | - | -> std::coroutine_handle<> | 154 | + | 2 | dispatch(std::coroutine_handle<> h, capy::executor_ref ex) const | |
| 193 | - | token_ = env->stop_token; | ||||||
| ECB | 194 | 4 | { | 155 | { | |||
| HITCBC | 195 | 12 | return acc_.get_impl().accept( | 156 | 6 | return acc_.get_impl().accept( | ||
| HITCBC | 196 | - | 12 | h, env->executor, token_, &ec_, &peer_impl_); | 157 | + | 6 | h, ex, this->token_, &this->ec_, &peer_impl_); |
| 197 | } | 158 | } | |||||
| 198 | }; | 159 | }; | |||||
| 199 | 160 | |||||||
| 200 | public: | 161 | public: | |||||
| 201 | /** Construct a native acceptor from an execution context. | 162 | /** Construct a native acceptor from an execution context. | |||||
| 202 | 163 | |||||||
| 203 | @param ctx The execution context that will own this acceptor. | 164 | @param ctx The execution context that will own this acceptor. | |||||
| 204 | */ | 165 | */ | |||||
| HITCBC | 205 | 18 | explicit native_local_stream_acceptor(capy::execution_context& ctx) | 166 | 18 | explicit native_local_stream_acceptor(capy::execution_context& ctx) | ||
| HITCBC | 206 | 18 | : local_stream_acceptor(create_handle<service_type>(ctx), ctx) | 167 | 18 | : local_stream_acceptor(create_handle<service_type>(ctx), ctx) | ||
| 207 | { | 168 | { | |||||
| HITCBC | 208 | 18 | } | 169 | 18 | } | ||
| 209 | 170 | |||||||
| 210 | /** Construct a native acceptor from an executor. | 171 | /** Construct a native acceptor from an executor. | |||||
| 211 | 172 | |||||||
| 212 | @param ex The executor whose context will own the acceptor. | 173 | @param ex The executor whose context will own the acceptor. | |||||
| 213 | */ | 174 | */ | |||||
| 214 | template<class Ex> | 175 | template<class Ex> | |||||
| 215 | requires(!std::same_as< | 176 | requires(!std::same_as< | |||||
| 216 | std::remove_cvref_t<Ex>, | 177 | std::remove_cvref_t<Ex>, | |||||
| 217 | native_local_stream_acceptor>) && | 178 | native_local_stream_acceptor>) && | |||||
| 218 | capy::Executor<Ex> | 179 | capy::Executor<Ex> | |||||
| 219 | explicit native_local_stream_acceptor(Ex const& ex) | 180 | explicit native_local_stream_acceptor(Ex const& ex) | |||||
| 220 | : native_local_stream_acceptor(ex.context()) | 181 | : native_local_stream_acceptor(ex.context()) | |||||
| 221 | { | 182 | { | |||||
| 222 | } | 183 | } | |||||
| 223 | 184 | |||||||
| 224 | /// Move construct. | 185 | /// Move construct. | |||||
| HITCBC | 225 | 2 | native_local_stream_acceptor(native_local_stream_acceptor&&) noexcept = | 186 | 2 | native_local_stream_acceptor(native_local_stream_acceptor&&) noexcept = | ||
| 226 | default; | 187 | default; | |||||
| 227 | 188 | |||||||
| 228 | /// Move assign. | 189 | /// Move assign. | |||||
| 229 | native_local_stream_acceptor& | 190 | native_local_stream_acceptor& | |||||
| 230 | operator=(native_local_stream_acceptor&&) noexcept = default; | 191 | operator=(native_local_stream_acceptor&&) noexcept = default; | |||||
| 231 | 192 | |||||||
| 232 | native_local_stream_acceptor(native_local_stream_acceptor const&) = delete; | 193 | native_local_stream_acceptor(native_local_stream_acceptor const&) = delete; | |||||
| 233 | native_local_stream_acceptor& | 194 | native_local_stream_acceptor& | |||||
| 234 | operator=(native_local_stream_acceptor const&) = delete; | 195 | operator=(native_local_stream_acceptor const&) = delete; | |||||
| 235 | 196 | |||||||
| 236 | /** Asynchronously accept an incoming connection. | 197 | /** Asynchronously accept an incoming connection. | |||||
| 237 | 198 | |||||||
| 238 | Calls the backend implementation directly, bypassing virtual | 199 | Calls the backend implementation directly, bypassing virtual | |||||
| 239 | dispatch. Otherwise identical to @ref local_stream_acceptor::accept. | 200 | dispatch. Otherwise identical to @ref local_stream_acceptor::accept. | |||||
| 240 | 201 | |||||||
| 241 | @param peer The socket to receive the accepted connection. | 202 | @param peer The socket to receive the accepted connection. | |||||
| 242 | 203 | |||||||
| 243 | @return An awaitable yielding `io_result<>`. | 204 | @return An awaitable yielding `io_result<>`. | |||||
| 244 | 205 | |||||||
| 245 | A closed acceptor reports `errc::bad_file_descriptor`. | 206 | A closed acceptor reports `errc::bad_file_descriptor`. | |||||
| 246 | 207 | |||||||
| 247 | Both this acceptor and @p peer must outlive the returned | 208 | Both this acceptor and @p peer must outlive the returned | |||||
| 248 | awaitable. | 209 | awaitable. | |||||
| 249 | */ | 210 | */ | |||||
| HITCBC | 250 | 8 | [[nodiscard]] auto accept(local_stream_socket& peer) | 211 | 8 | [[nodiscard]] auto accept(local_stream_socket& peer) | ||
| 251 | { | 212 | { | |||||
| HITCBC | 252 | 8 | native_accept_awaitable aw(*this, peer); | 213 | 8 | native_accept_awaitable aw(*this, peer); | ||
| HITCBC | 253 | 8 | if (!is_open()) | 214 | 8 | if (!is_open()) | ||
| HITCBC | 254 | 2 | aw.ec_ = make_error_code(std::errc::bad_file_descriptor); | 215 | 2 | aw.ec_ = make_error_code(std::errc::bad_file_descriptor); | ||
| HITCBC | 255 | 8 | return aw; | 216 | 8 | return aw; | ||
| 256 | } | 217 | } | |||||
| 257 | 218 | |||||||
| 258 | /** Asynchronously accept an incoming connection, returning the peer. | 219 | /** Asynchronously accept an incoming connection, returning the peer. | |||||
| 259 | 220 | |||||||
| 260 | Calls the backend implementation directly, bypassing virtual | 221 | Calls the backend implementation directly, bypassing virtual | |||||
| 261 | dispatch. The accepted peer is returned as a | 222 | dispatch. The accepted peer is returned as a | |||||
| 262 | @ref native_local_stream_socket so that subsequent I/O on it | 223 | @ref native_local_stream_socket so that subsequent I/O on it | |||||
| 263 | is also devirtualized. | 224 | is also devirtualized. | |||||
| 264 | 225 | |||||||
| 265 | @return An awaitable yielding | 226 | @return An awaitable yielding | |||||
| 266 | `io_result<native_local_stream_socket<Backend>>`. | 227 | `io_result<native_local_stream_socket<Backend>>`. | |||||
| 267 | 228 | |||||||
| 268 | A closed acceptor reports `errc::bad_file_descriptor`. | 229 | A closed acceptor reports `errc::bad_file_descriptor`. | |||||
| 269 | 230 | |||||||
| 270 | @throws std::logic_error If the acceptor has been moved from. | 231 | @throws std::logic_error If the acceptor has been moved from. | |||||
| 271 | 232 | |||||||
| 272 | This acceptor must outlive the returned awaitable. | 233 | This acceptor must outlive the returned awaitable. | |||||
| 273 | */ | 234 | */ | |||||
| HITCBC | 274 | 8 | [[nodiscard]] auto accept() | 235 | 8 | [[nodiscard]] auto accept() | ||
| 275 | { | 236 | { | |||||
| 276 | // The awaitable builds the peer from context(), which a | 237 | // The awaitable builds the peer from context(), which a | |||||
| 277 | // moved-from acceptor no longer has. | 238 | // moved-from acceptor no longer has. | |||||
| HITCBC | 278 | 8 | if (!h_) | 239 | 8 | if (!h_) | ||
| HITCBC | 279 | 2 | detail::throw_logic_error("accept: acceptor moved-from"); | 240 | 2 | detail::throw_logic_error("accept: acceptor moved-from"); | ||
| HITCBC | 280 | 6 | native_move_accept_awaitable aw(*this); | 241 | 6 | native_move_accept_awaitable aw(*this); | ||
| HITCBC | 281 | 6 | if (!is_open()) | 242 | 6 | if (!is_open()) | ||
| HITCBC | 282 | 2 | aw.ec_ = make_error_code(std::errc::bad_file_descriptor); | 243 | 2 | aw.ec_ = make_error_code(std::errc::bad_file_descriptor); | ||
| HITCBC | 283 | 6 | return aw; | 244 | 6 | return aw; | ||
| 284 | } | 245 | } | |||||
| 285 | 246 | |||||||
| 286 | /** Asynchronously wait for the acceptor to be ready. | 247 | /** Asynchronously wait for the acceptor to be ready. | |||||
| 287 | 248 | |||||||
| 288 | Calls the backend implementation directly, bypassing virtual | 249 | Calls the backend implementation directly, bypassing virtual | |||||
| 289 | dispatch. Otherwise identical to @ref local_stream_acceptor::wait. | 250 | dispatch. Otherwise identical to @ref local_stream_acceptor::wait. | |||||
| 290 | 251 | |||||||
| 291 | @param w The wait direction (typically `wait_type::read`). | 252 | @param w The wait direction (typically `wait_type::read`). | |||||
| 292 | 253 | |||||||
| 293 | @return An awaitable yielding `io_result<>`. | 254 | @return An awaitable yielding `io_result<>`. | |||||
| 294 | */ | 255 | */ | |||||
| HITCBC | 295 | 6 | [[nodiscard]] auto wait(wait_type w) | 256 | 6 | [[nodiscard]] auto wait(wait_type w) | ||
| 296 | { | 257 | { | |||||
| HITCBC | 297 | 6 | return native_wait_awaitable(*this, w); | 258 | 6 | return native_wait_awaitable(*this, w); | ||
| 298 | } | 259 | } | |||||
| 299 | }; | 260 | }; | |||||
| 300 | 261 | |||||||
| 301 | } // namespace boost::corosio | 262 | } // namespace boost::corosio | |||||
| 302 | 263 | |||||||
| 303 | #endif // BOOST_COROSIO_NATIVE_NATIVE_LOCAL_STREAM_ACCEPTOR_HPP | 264 | #endif // BOOST_COROSIO_NATIVE_NATIVE_LOCAL_STREAM_ACCEPTOR_HPP | |||||