Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / detail / completion_handler.hpp @ 2486

History | View | Annotate | Download (2.5 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// detail/completion_handler.hpp
3 2486 sjacqu01
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 2486 sjacqu01
//
5 2486 sjacqu01
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 2486 sjacqu01
//
7 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8 2486 sjacqu01
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 2486 sjacqu01
//
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_ASIO_DETAIL_COMPLETION_HANDLER_HPP
12 2486 sjacqu01
#define BOOST_ASIO_DETAIL_COMPLETION_HANDLER_HPP
13 2486 sjacqu01
14 2486 sjacqu01
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 2486 sjacqu01
# pragma once
16 2486 sjacqu01
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 2486 sjacqu01
18 2486 sjacqu01
#include <boost/asio/detail/addressof.hpp>
19 2486 sjacqu01
#include <boost/asio/detail/config.hpp>
20 2486 sjacqu01
#include <boost/asio/detail/fenced_block.hpp>
21 2486 sjacqu01
#include <boost/asio/detail/handler_alloc_helpers.hpp>
22 2486 sjacqu01
#include <boost/asio/detail/handler_invoke_helpers.hpp>
23 2486 sjacqu01
#include <boost/asio/detail/operation.hpp>
24 2486 sjacqu01
25 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
26 2486 sjacqu01
27 2486 sjacqu01
namespace boost {
28 2486 sjacqu01
namespace asio {
29 2486 sjacqu01
namespace detail {
30 2486 sjacqu01
31 2486 sjacqu01
template <typename Handler>
32 2486 sjacqu01
class completion_handler : public operation
33 2486 sjacqu01
{
34 2486 sjacqu01
public:
35 2486 sjacqu01
  BOOST_ASIO_DEFINE_HANDLER_PTR(completion_handler);
36 2486 sjacqu01
37 2486 sjacqu01
  completion_handler(Handler& h)
38 2486 sjacqu01
    : operation(&completion_handler::do_complete),
39 2486 sjacqu01
      handler_(BOOST_ASIO_MOVE_CAST(Handler)(h))
40 2486 sjacqu01
  {
41 2486 sjacqu01
  }
42 2486 sjacqu01
43 2486 sjacqu01
  static void do_complete(io_service_impl* owner, operation* base,
44 2486 sjacqu01
      const boost::system::error_code& /*ec*/,
45 2486 sjacqu01
      std::size_t /*bytes_transferred*/)
46 2486 sjacqu01
  {
47 2486 sjacqu01
    // Take ownership of the handler object.
48 2486 sjacqu01
    completion_handler* h(static_cast<completion_handler*>(base));
49 2486 sjacqu01
    ptr p = { boost::asio::detail::addressof(h->handler_), h, h };
50 2486 sjacqu01
51 2486 sjacqu01
    BOOST_ASIO_HANDLER_COMPLETION((h));
52 2486 sjacqu01
53 2486 sjacqu01
    // Make a copy of the handler so that the memory can be deallocated before
54 2486 sjacqu01
    // the upcall is made. Even if we're not about to make an upcall, a
55 2486 sjacqu01
    // sub-object of the handler may be the true owner of the memory associated
56 2486 sjacqu01
    // with the handler. Consequently, a local copy of the handler is required
57 2486 sjacqu01
    // to ensure that any owning sub-object remains valid until after we have
58 2486 sjacqu01
    // deallocated the memory here.
59 2486 sjacqu01
    Handler handler(BOOST_ASIO_MOVE_CAST(Handler)(h->handler_));
60 2486 sjacqu01
    p.h = boost::asio::detail::addressof(handler);
61 2486 sjacqu01
    p.reset();
62 2486 sjacqu01
63 2486 sjacqu01
    // Make the upcall if required.
64 2486 sjacqu01
    if (owner)
65 2486 sjacqu01
    {
66 2486 sjacqu01
      fenced_block b(fenced_block::half);
67 2486 sjacqu01
      BOOST_ASIO_HANDLER_INVOCATION_BEGIN(());
68 2486 sjacqu01
      boost_asio_handler_invoke_helpers::invoke(handler, handler);
69 2486 sjacqu01
      BOOST_ASIO_HANDLER_INVOCATION_END;
70 2486 sjacqu01
    }
71 2486 sjacqu01
  }
72 2486 sjacqu01
73 2486 sjacqu01
private:
74 2486 sjacqu01
  Handler handler_;
75 2486 sjacqu01
};
76 2486 sjacqu01
77 2486 sjacqu01
} // namespace detail
78 2486 sjacqu01
} // namespace asio
79 2486 sjacqu01
} // namespace boost
80 2486 sjacqu01
81 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
82 2486 sjacqu01
83 2486 sjacqu01
#endif // BOOST_ASIO_DETAIL_COMPLETION_HANDLER_HPP