Chris@16: // Chris@16: // windows/overlapped_ptr.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_HPP Chris@16: #define BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR) \ Chris@16: || defined(GENERATING_DOCUMENTATION) Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace windows { Chris@16: Chris@16: /// Wraps a handler to create an OVERLAPPED object for use with overlapped I/O. Chris@16: /** Chris@16: * A special-purpose smart pointer used to wrap an application handler so that Chris@16: * it can be passed as the LPOVERLAPPED argument to overlapped I/O functions. Chris@16: * Chris@16: * @par Thread Safety Chris@16: * @e Distinct @e objects: Safe.@n Chris@16: * @e Shared @e objects: Unsafe. Chris@16: */ Chris@16: class overlapped_ptr Chris@16: : private noncopyable Chris@16: { Chris@16: public: Chris@16: /// Construct an empty overlapped_ptr. Chris@16: overlapped_ptr() Chris@16: : impl_() Chris@16: { Chris@16: } Chris@16: Chris@16: /// Construct an overlapped_ptr to contain the specified handler. Chris@16: template Chris@16: explicit overlapped_ptr(boost::asio::io_service& io_service, Chris@16: BOOST_ASIO_MOVE_ARG(Handler) handler) Chris@16: : impl_(io_service, BOOST_ASIO_MOVE_CAST(Handler)(handler)) Chris@16: { Chris@16: } Chris@16: Chris@16: /// Destructor automatically frees the OVERLAPPED object unless released. Chris@16: ~overlapped_ptr() Chris@16: { Chris@16: } Chris@16: Chris@16: /// Reset to empty. Chris@16: void reset() Chris@16: { Chris@16: impl_.reset(); Chris@16: } Chris@16: Chris@16: /// Reset to contain the specified handler, freeing any current OVERLAPPED Chris@16: /// object. Chris@16: template Chris@16: void reset(boost::asio::io_service& io_service, Chris@16: BOOST_ASIO_MOVE_ARG(Handler) handler) Chris@16: { Chris@16: impl_.reset(io_service, BOOST_ASIO_MOVE_CAST(Handler)(handler)); Chris@16: } Chris@16: Chris@16: /// Get the contained OVERLAPPED object. Chris@16: OVERLAPPED* get() Chris@16: { Chris@16: return impl_.get(); Chris@16: } Chris@16: Chris@16: /// Get the contained OVERLAPPED object. Chris@16: const OVERLAPPED* get() const Chris@16: { Chris@16: return impl_.get(); Chris@16: } Chris@16: Chris@16: /// Release ownership of the OVERLAPPED object. Chris@16: OVERLAPPED* release() Chris@16: { Chris@16: return impl_.release(); Chris@16: } Chris@16: Chris@16: /// Post completion notification for overlapped operation. Releases ownership. Chris@16: void complete(const boost::system::error_code& ec, Chris@16: std::size_t bytes_transferred) Chris@16: { Chris@16: impl_.complete(ec, bytes_transferred); Chris@16: } Chris@16: Chris@16: private: Chris@16: detail::win_iocp_overlapped_ptr impl_; Chris@16: }; Chris@16: Chris@16: } // namespace windows Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR) Chris@16: // || defined(GENERATING_DOCUMENTATION) Chris@16: Chris@16: #endif // BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_HPP