src/corosio/src/resolver.cpp
100.0% Lines (8/8)
100.0% Functions (3/3)
| 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/resolver.hpp> | ||
| 12 | #include <boost/corosio/detail/platform.hpp> | ||
| 13 | |||
| 14 | #if BOOST_COROSIO_HAS_IOCP | ||
| 15 | #include <boost/corosio/native/detail/iocp/win_resolver_service.hpp> | ||
| 16 | #elif BOOST_COROSIO_POSIX | ||
| 17 | #include <boost/corosio/native/detail/posix/posix_resolver_service.hpp> | ||
| 18 | #endif | ||
| 19 | |||
| 20 | /* | ||
| 21 | Resolver Frontend | ||
| 22 | ================= | ||
| 23 | |||
| 24 | This file implements the public resolver class, which delegates to | ||
| 25 | platform-specific services: | ||
| 26 | - Windows: win_resolver_service (uses GetAddrInfoExW) | ||
| 27 | - POSIX: posix_resolver_service (uses getaddrinfo + worker threads) | ||
| 28 | |||
| 29 | The resolver constructor uses find_service() to locate the resolver | ||
| 30 | service, which must have been previously created by the scheduler | ||
| 31 | during io_context construction. If not found, construction fails. | ||
| 32 | |||
| 33 | This separation allows the public API to be platform-agnostic while | ||
| 34 | the implementation details are hidden in the detail namespace. | ||
| 35 | */ | ||
| 36 | |||
| 37 | namespace boost::corosio { | ||
| 38 | namespace { | ||
| 39 | |||
| 40 | #if BOOST_COROSIO_HAS_IOCP | ||
| 41 | using resolver_service = detail::win_resolver_service; | ||
| 42 | #elif BOOST_COROSIO_POSIX | ||
| 43 | using resolver_service = detail::posix_resolver_service; | ||
| 44 | #endif | ||
| 45 | |||
| 46 | } // namespace | ||
| 47 | |||
| 48 | 30 | resolver::~resolver() = default; | |
| 49 | |||
| 50 | 29 | resolver::resolver(capy::execution_context& ctx) | |
| 51 | 29 | : io_object(create_handle<resolver_service>(ctx)) | |
| 52 | { | ||
| 53 | 29 | } | |
| 54 | |||
| 55 | void | ||
| 56 | 4 | resolver::cancel() | |
| 57 | { | ||
| 58 | 4 | if (h_) | |
| 59 | 4 | get().cancel(); | |
| 60 | 4 | } | |
| 61 | |||
| 62 | } // namespace boost::corosio | ||
| 63 |