PageRenderTime 28ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/src/contrib/boost/asio/windows/overlapped_ptr.hpp

http://pythonocc.googlecode.com/
C++ Header | 120 lines | 70 code | 21 blank | 29 comment | 3 complexity | 050568b08c4d494ae3a95b59b8d60be8 MD5 | raw file
  1//
  2// overlapped_ptr.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_WINDOWS_OVERLAPPED_PTR_HPP
 12#define BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_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/io_service.hpp>
 21#include <boost/asio/detail/noncopyable.hpp>
 22#include <boost/asio/detail/win_iocp_overlapped_ptr.hpp>
 23
 24#if !defined(BOOST_ASIO_DISABLE_WINDOWS_OVERLAPPED_PTR)
 25# if defined(BOOST_ASIO_HAS_IOCP)
 26#  define BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR 1
 27# endif // defined(BOOST_ASIO_HAS_IOCP)
 28#endif // !defined(BOOST_ASIO_DISABLE_WINDOWS_OVERLAPPED_PTR)
 29
 30#if defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR) \
 31  || defined(GENERATING_DOCUMENTATION)
 32
 33namespace boost {
 34namespace asio {
 35namespace windows {
 36
 37/// Wraps a handler to create an OVERLAPPED object for use with overlapped I/O.
 38/**
 39 * A special-purpose smart pointer used to wrap an application handler so that
 40 * it can be passed as the LPOVERLAPPED argument to overlapped I/O functions.
 41 *
 42 * @par Thread Safety
 43 * @e Distinct @e objects: Safe.@n
 44 * @e Shared @e objects: Unsafe.
 45 */
 46class overlapped_ptr
 47  : private noncopyable
 48{
 49public:
 50  /// Construct an empty overlapped_ptr.
 51  overlapped_ptr()
 52    : impl_()
 53  {
 54  }
 55
 56  /// Construct an overlapped_ptr to contain the specified handler.
 57  template <typename Handler>
 58  explicit overlapped_ptr(boost::asio::io_service& io_service, Handler handler)
 59    : impl_(io_service, handler)
 60  {
 61  }
 62
 63  /// Destructor automatically frees the OVERLAPPED object unless released.
 64  ~overlapped_ptr()
 65  {
 66  }
 67
 68  /// Reset to empty.
 69  void reset()
 70  {
 71    impl_.reset();
 72  }
 73
 74  /// Reset to contain the specified handler, freeing any current OVERLAPPED
 75  /// object.
 76  template <typename Handler>
 77  void reset(boost::asio::io_service& io_service, Handler handler)
 78  {
 79    impl_.reset(io_service, handler);
 80  }
 81
 82  /// Get the contained OVERLAPPED object.
 83  OVERLAPPED* get()
 84  {
 85    return impl_.get();
 86  }
 87
 88  /// Get the contained OVERLAPPED object.
 89  const OVERLAPPED* get() const
 90  {
 91    return impl_.get();
 92  }
 93
 94  /// Release ownership of the OVERLAPPED object.
 95  OVERLAPPED* release()
 96  {
 97    return impl_.release();
 98  }
 99
100  /// Post completion notification for overlapped operation. Releases ownership.
101  void complete(const boost::system::error_code& ec,
102      std::size_t bytes_transferred)
103  {
104    impl_.complete(ec, bytes_transferred);
105  }
106
107private:
108  detail::win_iocp_overlapped_ptr impl_;
109};
110
111} // namespace windows
112} // namespace asio
113} // namespace boost
114
115#endif // defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
116       //   || defined(GENERATING_DOCUMENTATION)
117
118#include <boost/asio/detail/pop_options.hpp>
119
120#endif // BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_HPP