Realistic 3D camera system
3D camera system components
winrt_socket_recv_op.hpp
Go to the documentation of this file.
1 //
2 // detail/winrt_socket_recv_op.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 #ifndef ASIO_DETAIL_WINRT_SOCKET_RECV_OP_HPP
12 #define ASIO_DETAIL_WINRT_SOCKET_RECV_OP_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 
20 #if defined(ASIO_WINDOWS_RUNTIME)
21 
29 #include "asio/error.hpp"
30 
32 
33 namespace asio {
34 namespace detail {
35 
36 template <typename MutableBufferSequence, typename Handler>
37 class winrt_socket_recv_op :
38  public winrt_async_op<Windows::Storage::Streams::IBuffer^>
39 {
40 public:
41  ASIO_DEFINE_HANDLER_PTR(winrt_socket_recv_op);
42 
43  winrt_socket_recv_op(const MutableBufferSequence& buffers, Handler& handler)
44  : winrt_async_op<Windows::Storage::Streams::IBuffer^>(
45  &winrt_socket_recv_op::do_complete),
46  buffers_(buffers),
47  handler_(ASIO_MOVE_CAST(Handler)(handler))
48  {
49  }
50 
51  static void do_complete(io_service_impl* owner, operation* base,
52  const asio::error_code&, std::size_t)
53  {
54  // Take ownership of the operation object.
55  winrt_socket_recv_op* o(static_cast<winrt_socket_recv_op*>(base));
56  ptr p = { asio::detail::addressof(o->handler_), o, o };
57 
59 
60 #if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
61  // Check whether buffers are still valid.
62  if (owner)
63  {
64  buffer_sequence_adapter<asio::mutable_buffer,
65  MutableBufferSequence>::validate(o->buffers_);
66  }
67 #endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING)
68 
69  std::size_t bytes_transferred = o->result_ ? o->result_->Length : 0;
70  if (bytes_transferred == 0 && !o->ec_ &&
71  !buffer_sequence_adapter<asio::mutable_buffer,
72  MutableBufferSequence>::all_empty(o->buffers_))
73  {
74  o->ec_ = asio::error::eof;
75  }
76 
77  // Make a copy of the handler so that the memory can be deallocated before
78  // the upcall is made. Even if we're not about to make an upcall, a
79  // sub-object of the handler may be the true owner of the memory associated
80  // with the handler. Consequently, a local copy of the handler is required
81  // to ensure that any owning sub-object remains valid until after we have
82  // deallocated the memory here.
83  detail::binder2<Handler, asio::error_code, std::size_t>
84  handler(o->handler_, o->ec_, bytes_transferred);
85  p.h = asio::detail::addressof(handler.handler_);
86  p.reset();
87 
88  // Make the upcall if required.
89  if (owner)
90  {
92  ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
93  asio_handler_invoke_helpers::invoke(handler, handler.handler_);
95  }
96  }
97 
98 private:
99  MutableBufferSequence buffers_;
100  Handler handler_;
101 };
102 
103 } // namespace detail
104 } // namespace asio
105 
107 
108 #endif // defined(ASIO_WINDOWS_RUNTIME)
109 
110 #endif // ASIO_DETAIL_WINRT_SOCKET_RECV_OP_HPP
#define ASIO_HANDLER_INVOCATION_END
asio::basic_streambuf< Allocator > & b
Definition: read.hpp:702
null_fenced_block fenced_block
class task_io_service io_service_impl
Definition: io_service.hpp:48
End of file or stream.
Definition: error.hpp:217
void invoke(Function &function, Context &context)
const MutableBufferSequence & buffers
Definition: read.hpp:521
Holds a buffer that can be modified.
Definition: buffer.hpp:91
#define ASIO_HANDLER_INVOCATION_BEGIN(args)
Class to represent an error code value.
Definition: error_code.hpp:80
task_io_service_operation operation
Definition: operation.hpp:32
#define ASIO_DEFINE_HANDLER_PTR(op)
#define ASIO_HANDLER_COMPLETION(args)
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138