Chris@16: // Chris@16: // detail/winrt_resolve_op.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_DETAIL_WINRT_RESOLVE_OP_HPP Chris@16: #define BOOST_ASIO_DETAIL_WINRT_RESOLVE_OP_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_WINDOWS_RUNTIME) Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace detail { Chris@16: Chris@16: template Chris@16: class winrt_resolve_op : Chris@16: public winrt_async_op< Chris@16: Windows::Foundation::Collections::IVectorView< Chris@16: Windows::Networking::EndpointPair^>^> Chris@16: { Chris@16: public: Chris@16: BOOST_ASIO_DEFINE_HANDLER_PTR(winrt_resolve_op); Chris@16: Chris@16: typedef typename Protocol::endpoint endpoint_type; Chris@16: typedef boost::asio::ip::basic_resolver_query query_type; Chris@16: typedef boost::asio::ip::basic_resolver_iterator iterator_type; Chris@16: Chris@16: winrt_resolve_op(const query_type& query, Handler& handler) Chris@16: : winrt_async_op< Chris@16: Windows::Foundation::Collections::IVectorView< Chris@16: Windows::Networking::EndpointPair^>^>( Chris@16: &winrt_resolve_op::do_complete), Chris@16: query_(query), Chris@16: handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler)) Chris@16: { Chris@16: } Chris@16: Chris@16: static void do_complete(io_service_impl* owner, operation* base, Chris@16: const boost::system::error_code&, std::size_t) Chris@16: { Chris@16: // Take ownership of the operation object. Chris@16: winrt_resolve_op* o(static_cast(base)); Chris@16: ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; Chris@16: Chris@16: BOOST_ASIO_HANDLER_COMPLETION((o)); Chris@16: Chris@16: iterator_type iterator = iterator_type(); Chris@16: if (!o->ec_) Chris@16: { Chris@16: try Chris@16: { Chris@16: iterator = iterator_type::create( Chris@16: o->result_, o->query_.hints(), Chris@16: o->query_.host_name(), o->query_.service_name()); Chris@16: } Chris@16: catch (Platform::Exception^ e) Chris@16: { Chris@16: o->ec_ = boost::system::error_code(e->HResult, Chris@16: boost::system::system_category()); Chris@16: } Chris@16: } Chris@16: Chris@16: // Make a copy of the handler so that the memory can be deallocated before Chris@16: // the upcall is made. Even if we're not about to make an upcall, a Chris@16: // sub-object of the handler may be the true owner of the memory associated Chris@16: // with the handler. Consequently, a local copy of the handler is required Chris@16: // to ensure that any owning sub-object remains valid until after we have Chris@16: // deallocated the memory here. Chris@16: detail::binder2 Chris@16: handler(o->handler_, o->ec_, iterator); Chris@16: p.h = boost::asio::detail::addressof(handler.handler_); Chris@16: p.reset(); Chris@16: Chris@16: // Make the upcall if required. Chris@16: if (owner) Chris@16: { Chris@16: fenced_block b(fenced_block::half); Chris@16: BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); Chris@16: boost_asio_handler_invoke_helpers::invoke(handler, handler.handler_); Chris@16: BOOST_ASIO_HANDLER_INVOCATION_END; Chris@16: } Chris@16: } Chris@16: Chris@16: private: Chris@16: query_type query_; Chris@16: Handler handler_; Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) Chris@16: Chris@16: #endif // BOOST_ASIO_DETAIL_WINRT_RESOLVE_OP_HPP