libs/corosio/src/corosio/src/resolver.cpp
94.4% Lines (17/18)
100.0% Functions (3/3)
62.5% Branches (5/8)
libs/corosio/src/corosio/src/resolver.cpp
| Line | Branch | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com) | ||
| 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 | #include <boost/corosio/resolver.hpp> | ||
| 11 | #include <boost/corosio/detail/platform.hpp> | ||
| 12 | |||
| 13 | #if BOOST_COROSIO_HAS_IOCP | ||
| 14 | #include "src/detail/iocp/resolver_service.hpp" | ||
| 15 | #elif BOOST_COROSIO_POSIX | ||
| 16 | #include "src/detail/posix/resolver_service.hpp" | ||
| 17 | #endif | ||
| 18 | |||
| 19 | #include <stdexcept> | ||
| 20 | |||
| 21 | /* | ||
| 22 | Resolver Frontend | ||
| 23 | ================= | ||
| 24 | |||
| 25 | This file implements the public resolver class, which delegates to | ||
| 26 | platform-specific services: | ||
| 27 | - Windows: win_resolver_service (uses GetAddrInfoExW) | ||
| 28 | - POSIX: posix_resolver_service (uses getaddrinfo + worker threads) | ||
| 29 | |||
| 30 | The resolver constructor uses find_service() to locate the resolver | ||
| 31 | service, which must have been previously created by the scheduler | ||
| 32 | during io_context construction. If not found, construction fails. | ||
| 33 | |||
| 34 | This separation allows the public API to be platform-agnostic while | ||
| 35 | the implementation details are hidden in the detail namespace. | ||
| 36 | */ | ||
| 37 | |||
| 38 | namespace boost::corosio { | ||
| 39 | namespace { | ||
| 40 | |||
| 41 | #if BOOST_COROSIO_HAS_IOCP | ||
| 42 | using resolver_service = detail::win_resolver_service; | ||
| 43 | #elif BOOST_COROSIO_POSIX | ||
| 44 | using resolver_service = detail::posix_resolver_service; | ||
| 45 | #endif | ||
| 46 | |||
| 47 | } // namespace | ||
| 48 | |||
| 49 | 30 | resolver:: | |
| 50 | 30 | ~resolver() | |
| 51 | { | ||
| 52 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 2 times.
|
30 | if (impl_) |
| 53 | 28 | impl_->release(); | |
| 54 | 30 | } | |
| 55 | |||
| 56 | 29 | resolver:: | |
| 57 | resolver( | ||
| 58 | 29 | capy::execution_context& ctx) | |
| 59 | 29 | : io_object(ctx) | |
| 60 | { | ||
| 61 | 29 | auto* svc = ctx_->find_service<resolver_service>(); | |
| 62 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
|
29 | if (!svc) |
| 63 | { | ||
| 64 | // Resolver service not yet created - this happens if io_context | ||
| 65 | // hasn't been constructed yet, or if the scheduler didn't | ||
| 66 | // initialize the resolver service | ||
| 67 | ✗ | throw std::runtime_error("resolver_service not found"); | |
| 68 | } | ||
| 69 |
1/1✓ Branch 1 taken 29 times.
|
29 | auto& impl = svc->create_impl(); |
| 70 | 29 | impl_ = &impl; | |
| 71 | 29 | } | |
| 72 | |||
| 73 | void | ||
| 74 | 5 | resolver:: | |
| 75 | cancel() | ||
| 76 | { | ||
| 77 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (impl_) |
| 78 | 5 | get().cancel(); | |
| 79 | 5 | } | |
| 80 | |||
| 81 | } // namespace boost::corosio | ||
| 82 |