annotate DEPENDENCIES/generic/include/boost/asio/detail/winrt_resolver_service.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // detail/winrt_resolver_service.hpp
Chris@16 3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Chris@16 4 //
Chris@101 5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
Chris@16 6 //
Chris@16 7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9 //
Chris@16 10
Chris@16 11 #ifndef BOOST_ASIO_DETAIL_WINRT_RESOLVER_SERVICE_HPP
Chris@16 12 #define BOOST_ASIO_DETAIL_WINRT_RESOLVER_SERVICE_HPP
Chris@16 13
Chris@16 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 15 # pragma once
Chris@16 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 17
Chris@16 18 #include <boost/asio/detail/config.hpp>
Chris@16 19
Chris@16 20 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
Chris@16 21
Chris@16 22 #include <boost/asio/ip/basic_resolver_iterator.hpp>
Chris@16 23 #include <boost/asio/ip/basic_resolver_query.hpp>
Chris@16 24 #include <boost/asio/detail/addressof.hpp>
Chris@16 25 #include <boost/asio/detail/bind_handler.hpp>
Chris@16 26 #include <boost/asio/detail/socket_ops.hpp>
Chris@16 27 #include <boost/asio/detail/winrt_async_manager.hpp>
Chris@16 28 #include <boost/asio/detail/winrt_resolve_op.hpp>
Chris@16 29 #include <boost/asio/detail/winrt_utils.hpp>
Chris@16 30
Chris@16 31 #include <boost/asio/detail/push_options.hpp>
Chris@16 32
Chris@16 33 namespace boost {
Chris@16 34 namespace asio {
Chris@16 35 namespace detail {
Chris@16 36
Chris@16 37 template <typename Protocol>
Chris@16 38 class winrt_resolver_service
Chris@16 39 {
Chris@16 40 public:
Chris@16 41 // The implementation type of the resolver. A cancellation token is used to
Chris@16 42 // indicate to the asynchronous operation that the operation has been
Chris@16 43 // cancelled.
Chris@16 44 typedef socket_ops::shared_cancel_token_type implementation_type;
Chris@16 45
Chris@16 46 // The endpoint type.
Chris@16 47 typedef typename Protocol::endpoint endpoint_type;
Chris@16 48
Chris@16 49 // The query type.
Chris@16 50 typedef boost::asio::ip::basic_resolver_query<Protocol> query_type;
Chris@16 51
Chris@16 52 // The iterator type.
Chris@16 53 typedef boost::asio::ip::basic_resolver_iterator<Protocol> iterator_type;
Chris@16 54
Chris@16 55 // Constructor.
Chris@16 56 winrt_resolver_service(boost::asio::io_service& io_service)
Chris@16 57 : io_service_(use_service<io_service_impl>(io_service)),
Chris@16 58 async_manager_(use_service<winrt_async_manager>(io_service))
Chris@16 59 {
Chris@16 60 }
Chris@16 61
Chris@16 62 // Destructor.
Chris@16 63 ~winrt_resolver_service()
Chris@16 64 {
Chris@16 65 }
Chris@16 66
Chris@16 67 // Destroy all user-defined handler objects owned by the service.
Chris@16 68 void shutdown_service()
Chris@16 69 {
Chris@16 70 }
Chris@16 71
Chris@16 72 // Perform any fork-related housekeeping.
Chris@16 73 void fork_service(boost::asio::io_service::fork_event)
Chris@16 74 {
Chris@16 75 }
Chris@16 76
Chris@16 77 // Construct a new resolver implementation.
Chris@16 78 void construct(implementation_type&)
Chris@16 79 {
Chris@16 80 }
Chris@16 81
Chris@16 82 // Destroy a resolver implementation.
Chris@16 83 void destroy(implementation_type&)
Chris@16 84 {
Chris@16 85 }
Chris@16 86
Chris@16 87 // Cancel pending asynchronous operations.
Chris@16 88 void cancel(implementation_type&)
Chris@16 89 {
Chris@16 90 }
Chris@16 91
Chris@16 92 // Resolve a query to a list of entries.
Chris@16 93 iterator_type resolve(implementation_type&,
Chris@16 94 const query_type& query, boost::system::error_code& ec)
Chris@16 95 {
Chris@16 96 try
Chris@16 97 {
Chris@16 98 using namespace Windows::Networking::Sockets;
Chris@16 99 auto endpoint_pairs = async_manager_.sync(
Chris@16 100 DatagramSocket::GetEndpointPairsAsync(
Chris@16 101 winrt_utils::host_name(query.host_name()),
Chris@16 102 winrt_utils::string(query.service_name())), ec);
Chris@16 103
Chris@16 104 if (ec)
Chris@16 105 return iterator_type();
Chris@16 106
Chris@16 107 return iterator_type::create(
Chris@16 108 endpoint_pairs, query.hints(),
Chris@16 109 query.host_name(), query.service_name());
Chris@16 110 }
Chris@16 111 catch (Platform::Exception^ e)
Chris@16 112 {
Chris@16 113 ec = boost::system::error_code(e->HResult,
Chris@16 114 boost::system::system_category());
Chris@16 115 return iterator_type();
Chris@16 116 }
Chris@16 117 }
Chris@16 118
Chris@16 119 // Asynchronously resolve a query to a list of entries.
Chris@16 120 template <typename Handler>
Chris@16 121 void async_resolve(implementation_type&,
Chris@16 122 const query_type& query, Handler& handler)
Chris@16 123 {
Chris@16 124 bool is_continuation =
Chris@16 125 boost_asio_handler_cont_helpers::is_continuation(handler);
Chris@16 126
Chris@16 127 // Allocate and construct an operation to wrap the handler.
Chris@16 128 typedef winrt_resolve_op<Protocol, Handler> op;
Chris@16 129 typename op::ptr p = { boost::asio::detail::addressof(handler),
Chris@16 130 boost_asio_handler_alloc_helpers::allocate(
Chris@16 131 sizeof(op), handler), 0 };
Chris@16 132 p.p = new (p.v) op(query, handler);
Chris@16 133
Chris@16 134 BOOST_ASIO_HANDLER_CREATION((p.p, "resolver", &impl, "async_resolve"));
Chris@16 135
Chris@16 136 try
Chris@16 137 {
Chris@16 138 using namespace Windows::Networking::Sockets;
Chris@16 139 async_manager_.async(DatagramSocket::GetEndpointPairsAsync(
Chris@16 140 winrt_utils::host_name(query.host_name()),
Chris@16 141 winrt_utils::string(query.service_name())), p.p);
Chris@16 142 p.v = p.p = 0;
Chris@16 143 }
Chris@16 144 catch (Platform::Exception^ e)
Chris@16 145 {
Chris@16 146 p.p->ec_ = boost::system::error_code(
Chris@16 147 e->HResult, boost::system::system_category());
Chris@16 148 io_service_.post_immediate_completion(p.p, is_continuation);
Chris@16 149 p.v = p.p = 0;
Chris@16 150 }
Chris@16 151 }
Chris@16 152
Chris@16 153 // Resolve an endpoint to a list of entries.
Chris@16 154 iterator_type resolve(implementation_type&,
Chris@16 155 const endpoint_type&, boost::system::error_code& ec)
Chris@16 156 {
Chris@16 157 ec = boost::asio::error::operation_not_supported;
Chris@16 158 return iterator_type();
Chris@16 159 }
Chris@16 160
Chris@16 161 // Asynchronously resolve an endpoint to a list of entries.
Chris@16 162 template <typename Handler>
Chris@16 163 void async_resolve(implementation_type&,
Chris@16 164 const endpoint_type&, Handler& handler)
Chris@16 165 {
Chris@16 166 boost::system::error_code ec = boost::asio::error::operation_not_supported;
Chris@16 167 const iterator_type iterator;
Chris@16 168 io_service_.get_io_service().post(
Chris@16 169 detail::bind_handler(handler, ec, iterator));
Chris@16 170 }
Chris@16 171
Chris@16 172 private:
Chris@16 173 io_service_impl& io_service_;
Chris@16 174 winrt_async_manager& async_manager_;
Chris@16 175 };
Chris@16 176
Chris@16 177 } // namespace detail
Chris@16 178 } // namespace asio
Chris@16 179 } // namespace boost
Chris@16 180
Chris@16 181 #include <boost/asio/detail/pop_options.hpp>
Chris@16 182
Chris@16 183 #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
Chris@16 184
Chris@16 185 #endif // BOOST_ASIO_DETAIL_WINRT_RESOLVER_SERVICE_HPP