PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/src/contrib/boost/asio/detail/null_buffers_op.hpp

http://pythonocc.googlecode.com/
C++ Header | 79 lines | 49 code | 13 blank | 17 comment | 2 complexity | e9e4c4040111e22d91391f9249f10b6a MD5 | raw file
 1//
 2// null_buffers_op.hpp
 3// ~~~~~~~~~~~~~~~~~~~
 4//
 5// Copyright (c) 2003-2010 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 BOOST_ASIO_DETAIL_NULL_BUFFERS_OP_HPP
12#define BOOST_ASIO_DETAIL_NULL_BUFFERS_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 <boost/asio/detail/push_options.hpp>
19
20#include <boost/asio/detail/fenced_block.hpp>
21#include <boost/asio/detail/handler_alloc_helpers.hpp>
22#include <boost/asio/detail/handler_invoke_helpers.hpp>
23#include <boost/asio/detail/reactor_op.hpp>
24
25namespace boost {
26namespace asio {
27namespace detail {
28
29template <typename Handler>
30class null_buffers_op : public reactor_op
31{
32public:
33  null_buffers_op(Handler handler)
34    : reactor_op(&null_buffers_op::do_perform, &null_buffers_op::do_complete),
35      handler_(handler)
36  {
37  }
38
39  static bool do_perform(reactor_op*)
40  {
41    return true;
42  }
43
44  static void do_complete(io_service_impl* owner, operation* base,
45      boost::system::error_code /*ec*/, std::size_t /*bytes_transferred*/)
46  {
47    // Take ownership of the handler object.
48    null_buffers_op* o(static_cast<null_buffers_op*>(base));
49    typedef handler_alloc_traits<Handler, null_buffers_op> alloc_traits;
50    handler_ptr<alloc_traits> ptr(o->handler_, o);
51
52    // Make the upcall if required.
53    if (owner)
54    {
55      // Make a copy of the handler so that the memory can be deallocated
56      // before the upcall is made. Even if we're not about to make an upcall,
57      // a sub-object of the handler may be the true owner of the memory
58      // associated with the handler. Consequently, a local copy of the handler
59      // is required to ensure that any owning sub-object remains valid until
60      // after we have deallocated the memory here.
61      detail::binder2<Handler, boost::system::error_code, std::size_t>
62        handler(o->handler_, o->ec_, o->bytes_transferred_);
63      ptr.reset();
64      boost::asio::detail::fenced_block b;
65      boost_asio_handler_invoke_helpers::invoke(handler, handler);
66    }
67  }
68
69private:
70  Handler handler_;
71};
72
73} // namespace detail
74} // namespace asio
75} // namespace boost
76
77#include <boost/asio/detail/pop_options.hpp>
78
79#endif // BOOST_ASIO_DETAIL_NULL_BUFFERS_OP_HPP