File indexing completed on 2026-08-17 08:39:19
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_COBALT_RESOLVER_HPP
0010 #define BOOST_COBALT_RESOLVER_HPP
0011
0012 #include <boost/cobalt/io/detail/config.hpp>
0013 #include <boost/cobalt/io/endpoint.hpp>
0014 #include <boost/cobalt/io/ops.hpp>
0015 #include <boost/cobalt/op.hpp>
0016 #include <boost/cobalt/promise.hpp>
0017
0018 #include <boost/asio/ip/tcp.hpp>
0019 #include <boost/system/result.hpp>
0020
0021 namespace boost::cobalt::io
0022 {
0023
0024 struct BOOST_SYMBOL_VISIBLE resolver
0025 {
0026 using flags = asio::ip::resolver_base::flags;
0027
0028 resolver(const executor & exec = this_thread::get_executor());
0029 resolver(resolver && ) = delete;
0030
0031 void cancel();
0032
0033 private:
0034 struct BOOST_COBALT_IO_DECL resolve_op_ final : op<system::error_code, endpoint_sequence>
0035 {
0036 void initiate(completion_handler<system::error_code, endpoint_sequence> h) override;
0037
0038 resolve_op_(asio::ip::basic_resolver<protocol_type, executor> & resolver,
0039 std::string_view host, std::string_view service, flags flags_ = {})
0040 : resolver_(resolver), host_(host), service_(service), flags_(flags_) {}
0041 ~resolve_op_() = default;
0042 private:
0043 asio::ip::basic_resolver<protocol_type, executor> & resolver_;
0044 std::string_view host_;
0045 std::string_view service_;
0046 flags flags_;
0047 };
0048
0049 public:
0050 [[nodiscard]] auto resolve(std::string_view host, std::string_view service,
0051 flags flags_ = {})
0052 {
0053 return resolve_op_{resolver_, host, service, flags_};
0054 }
0055
0056 private:
0057 asio::ip::basic_resolver<protocol_type, executor> resolver_;
0058 };
0059
0060 struct BOOST_COBALT_IO_DECL lookup final : op<system::error_code, endpoint_sequence>
0061 {
0062 lookup(std::string_view host, std::string_view service,
0063 const executor & exec = this_thread::get_executor(),
0064 resolver::flags flags_ = {})
0065 : host_(host), service_(service), resolver_{exec}, flags_{flags_} {}
0066
0067 void initiate(completion_handler<system::error_code, endpoint_sequence> h) final override;
0068 ~lookup() = default;
0069 private:
0070 std::string_view host_;
0071 std::string_view service_;
0072 asio::ip::basic_resolver<protocol_type, executor> resolver_;
0073 resolver::flags flags_;
0074 };
0075
0076 }
0077
0078 #endif