File indexing completed on 2025-01-18 09:28:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_WINRT_SOCKET_RECV_OP_HPP
0012 #define BOOST_ASIO_DETAIL_WINRT_SOCKET_RECV_OP_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019
0020 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
0021
0022 #include <boost/asio/detail/bind_handler.hpp>
0023 #include <boost/asio/detail/buffer_sequence_adapter.hpp>
0024 #include <boost/asio/detail/fenced_block.hpp>
0025 #include <boost/asio/detail/handler_alloc_helpers.hpp>
0026 #include <boost/asio/detail/handler_work.hpp>
0027 #include <boost/asio/detail/memory.hpp>
0028 #include <boost/asio/detail/winrt_async_op.hpp>
0029 #include <boost/asio/error.hpp>
0030
0031 #include <boost/asio/detail/push_options.hpp>
0032
0033 namespace boost {
0034 namespace asio {
0035 namespace detail {
0036
0037 template <typename MutableBufferSequence, typename Handler, typename IoExecutor>
0038 class winrt_socket_recv_op :
0039 public winrt_async_op<Windows::Storage::Streams::IBuffer^>
0040 {
0041 public:
0042 BOOST_ASIO_DEFINE_HANDLER_PTR(winrt_socket_recv_op);
0043
0044 winrt_socket_recv_op(const MutableBufferSequence& buffers,
0045 Handler& handler, const IoExecutor& io_ex)
0046 : winrt_async_op<Windows::Storage::Streams::IBuffer^>(
0047 &winrt_socket_recv_op::do_complete),
0048 buffers_(buffers),
0049 handler_(static_cast<Handler&&>(handler)),
0050 work_(handler_, io_ex)
0051 {
0052 }
0053
0054 static void do_complete(void* owner, operation* base,
0055 const boost::system::error_code&, std::size_t)
0056 {
0057
0058 BOOST_ASIO_ASSUME(base != 0);
0059 winrt_socket_recv_op* o(static_cast<winrt_socket_recv_op*>(base));
0060 ptr p = { boost::asio::detail::addressof(o->handler_), o, o };
0061
0062 BOOST_ASIO_HANDLER_COMPLETION((*o));
0063
0064
0065 handler_work<Handler, IoExecutor> w(
0066 static_cast<handler_work<Handler, IoExecutor>&&>(
0067 o->work_));
0068
0069 #if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
0070
0071 if (owner)
0072 {
0073 buffer_sequence_adapter<boost::asio::mutable_buffer,
0074 MutableBufferSequence>::validate(o->buffers_);
0075 }
0076 #endif
0077
0078 std::size_t bytes_transferred = o->result_ ? o->result_->Length : 0;
0079 if (bytes_transferred == 0 && !o->ec_ &&
0080 !buffer_sequence_adapter<boost::asio::mutable_buffer,
0081 MutableBufferSequence>::all_empty(o->buffers_))
0082 {
0083 o->ec_ = boost::asio::error::eof;
0084 }
0085
0086
0087
0088
0089
0090
0091
0092 detail::binder2<Handler, boost::system::error_code, std::size_t>
0093 handler(o->handler_, o->ec_, bytes_transferred);
0094 p.h = boost::asio::detail::addressof(handler.handler_);
0095 p.reset();
0096
0097
0098 if (owner)
0099 {
0100 fenced_block b(fenced_block::half);
0101 BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
0102 w.complete(handler, handler.handler_);
0103 BOOST_ASIO_HANDLER_INVOCATION_END;
0104 }
0105 }
0106
0107 private:
0108 MutableBufferSequence buffers_;
0109 Handler handler_;
0110 handler_work<Handler, IoExecutor> executor_;
0111 };
0112
0113 }
0114 }
0115 }
0116
0117 #include <boost/asio/detail/pop_options.hpp>
0118
0119 #endif
0120
0121 #endif