PageRenderTime 22ms CodeModel.GetById 16ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/asio/detail/win_iocp_overlapped_op.hpp

http://hadesmem.googlecode.com/
C++ Header | 90 lines | 55 code | 18 blank | 17 comment | 2 complexity | 46b8befc9e2ad36793a9f8ca3f639e3e MD5 | raw file
 1//
 2// detail/win_iocp_overlapped_op.hpp
 3// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 4//
 5// Copyright (c) 2003-2011 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_WIN_IOCP_OVERLAPPED_OP_HPP
12#define BOOST_ASIO_DETAIL_WIN_IOCP_OVERLAPPED_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/config.hpp>
19
20#if defined(BOOST_ASIO_HAS_IOCP)
21
22#include <boost/asio/error.hpp>
23#include <boost/utility/addressof.hpp>
24#include <boost/asio/detail/bind_handler.hpp>
25#include <boost/asio/detail/fenced_block.hpp>
26#include <boost/asio/detail/handler_alloc_helpers.hpp>
27#include <boost/asio/detail/handler_invoke_helpers.hpp>
28#include <boost/asio/detail/operation.hpp>
29
30#include <boost/asio/detail/push_options.hpp>
31
32namespace boost {
33namespace asio {
34namespace detail {
35
36template <typename Handler>
37class win_iocp_overlapped_op : public operation
38{
39public:
40  BOOST_ASIO_DEFINE_HANDLER_PTR(win_iocp_overlapped_op);
41
42  win_iocp_overlapped_op(Handler& handler)
43    : operation(&win_iocp_overlapped_op::do_complete),
44      handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler))
45  {
46  }
47
48  static void do_complete(io_service_impl* owner, operation* base,
49      boost::system::error_code ec, std::size_t bytes_transferred)
50  {
51    // Take ownership of the operation object.
52    win_iocp_overlapped_op* o(static_cast<win_iocp_overlapped_op*>(base));
53    ptr p = { boost::addressof(o->handler_), o, o };
54
55    BOOST_ASIO_HANDLER_COMPLETION((o));
56
57    // Make a copy of the handler so that the memory can be deallocated before
58    // the upcall is made. Even if we're not about to make an upcall, a
59    // sub-object of the handler may be the true owner of the memory associated
60    // with the handler. Consequently, a local copy of the handler is required
61    // to ensure that any owning sub-object remains valid until after we have
62    // deallocated the memory here.
63    detail::binder2<Handler, boost::system::error_code, std::size_t>
64      handler(o->handler_, ec, bytes_transferred);
65    p.h = boost::addressof(handler.handler_);
66    p.reset();
67
68    // Make the upcall if required.
69    if (owner)
70    {
71      boost::asio::detail::fenced_block b;
72      BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
73      boost_asio_handler_invoke_helpers::invoke(handler, handler.handler_);
74      BOOST_ASIO_HANDLER_INVOCATION_END;
75    }
76  }
77
78private:
79  Handler handler_;
80};
81
82} // namespace detail
83} // namespace asio
84} // namespace boost
85
86#include <boost/asio/detail/pop_options.hpp>
87
88#endif // defined(BOOST_ASIO_HAS_IOCP)
89
90#endif // BOOST_ASIO_DETAIL_WIN_IOCP_OVERLAPPED_OP_HPP