src/corosio/src/resolver.cpp

100.0% Lines (9/9) 100.0% Functions (3/3) 66.7% Branches (2/3)
src/corosio/src/resolver.cpp
Line Branch Hits Source Code
1 //
2 // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.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 ~resolver() = default;
51
52 29 resolver::
53 resolver(
54 29 capy::execution_context& ctx)
55
1/1
✓ Branch 1 taken 29 times.
29 : io_object(create_handle<resolver_service>(ctx))
56 {
57 29 }
58
59 void
60 4 resolver::
61 cancel()
62 {
63
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 if (h_)
64 4 get().cancel();
65 4 }
66
67 } // namespace boost::corosio
68