Chris@16: // Chris@16: // windows/basic_object_handle.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Copyright (c) 2011 Boris Schaeling (boris@highscore.de) 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_BASIC_OBJECT_HANDLE_HPP Chris@16: #define BOOST_ASIO_WINDOWS_BASIC_OBJECT_HANDLE_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_OBJECT_HANDLE) \ Chris@16: || defined(GENERATING_DOCUMENTATION) Chris@16: Chris@16: #include 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: /// Provides object-oriented handle functionality. Chris@16: /** Chris@16: * The windows::basic_object_handle class template provides asynchronous and Chris@16: * blocking object-oriented handle functionality. 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: template Chris@16: class basic_object_handle Chris@16: : public basic_handle Chris@16: { Chris@16: public: Chris@16: /// The native representation of a handle. Chris@16: typedef typename ObjectHandleService::native_handle_type native_handle_type; Chris@16: Chris@16: /// Construct a basic_object_handle without opening it. Chris@16: /** Chris@16: * This constructor creates an object handle without opening it. Chris@16: * Chris@16: * @param io_service The io_service object that the object handle will use to Chris@16: * dispatch handlers for any asynchronous operations performed on the handle. Chris@16: */ Chris@16: explicit basic_object_handle(boost::asio::io_service& io_service) Chris@16: : basic_handle(io_service) Chris@16: { Chris@16: } Chris@16: Chris@16: /// Construct a basic_object_handle on an existing native handle. Chris@16: /** Chris@16: * This constructor creates an object handle object to hold an existing native Chris@16: * handle. Chris@16: * Chris@16: * @param io_service The io_service object that the object handle will use to Chris@16: * dispatch handlers for any asynchronous operations performed on the handle. Chris@16: * Chris@16: * @param native_handle The new underlying handle implementation. Chris@16: * Chris@16: * @throws boost::system::system_error Thrown on failure. Chris@16: */ Chris@16: basic_object_handle(boost::asio::io_service& io_service, Chris@16: const native_handle_type& native_handle) Chris@16: : basic_handle(io_service, native_handle) Chris@16: { Chris@16: } Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) Chris@16: /// Move-construct a basic_object_handle from another. Chris@16: /** Chris@16: * This constructor moves an object handle from one object to another. Chris@16: * Chris@16: * @param other The other basic_object_handle object from which the move will Chris@16: * occur. Chris@16: * Chris@16: * @note Following the move, the moved-from object is in the same state as if Chris@16: * constructed using the @c basic_object_handle(io_service&) constructor. Chris@16: */ Chris@16: basic_object_handle(basic_object_handle&& other) Chris@16: : basic_handle( Chris@16: BOOST_ASIO_MOVE_CAST(basic_object_handle)(other)) Chris@16: { Chris@16: } Chris@16: Chris@16: /// Move-assign a basic_object_handle from another. Chris@16: /** Chris@16: * This assignment operator moves an object handle from one object to another. Chris@16: * Chris@16: * @param other The other basic_object_handle object from which the move will Chris@16: * occur. Chris@16: * Chris@16: * @note Following the move, the moved-from object is in the same state as if Chris@16: * constructed using the @c basic_object_handle(io_service&) constructor. Chris@16: */ Chris@16: basic_object_handle& operator=(basic_object_handle&& other) Chris@16: { Chris@16: basic_handle::operator=( Chris@16: BOOST_ASIO_MOVE_CAST(basic_object_handle)(other)); Chris@16: return *this; Chris@16: } Chris@16: #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) Chris@16: Chris@16: /// Perform a blocking wait on the object handle. Chris@16: /** Chris@16: * This function is used to wait for the object handle to be set to the Chris@16: * signalled state. This function blocks and does not return until the object Chris@16: * handle has been set to the signalled state. Chris@16: * Chris@16: * @throws boost::system::system_error Thrown on failure. Chris@16: */ Chris@16: void wait() Chris@16: { Chris@16: boost::system::error_code ec; Chris@16: this->get_service().wait(this->get_implementation(), ec); Chris@16: boost::asio::detail::throw_error(ec, "wait"); Chris@16: } Chris@16: Chris@16: /// Perform a blocking wait on the object handle. Chris@16: /** Chris@16: * This function is used to wait for the object handle to be set to the Chris@16: * signalled state. This function blocks and does not return until the object Chris@16: * handle has been set to the signalled state. Chris@16: * Chris@16: * @param ec Set to indicate what error occurred, if any. Chris@16: */ Chris@16: void wait(boost::system::error_code& ec) Chris@16: { Chris@16: this->get_service().wait(this->get_implementation(), ec); Chris@16: } Chris@16: Chris@16: /// Start an asynchronous wait on the object handle. Chris@16: /** Chris@16: * This function is be used to initiate an asynchronous wait against the Chris@16: * object handle. It always returns immediately. Chris@16: * Chris@16: * @param handler The handler to be called when the object handle is set to Chris@16: * the signalled state. Copies will be made of the handler as required. The Chris@16: * function signature of the handler must be: Chris@16: * @code void handler( Chris@16: * const boost::system::error_code& error // Result of operation. Chris@16: * ); @endcode Chris@16: * Regardless of whether the asynchronous operation completes immediately or Chris@16: * not, the handler will not be invoked from within this function. Invocation Chris@16: * of the handler will be performed in a manner equivalent to using Chris@16: * boost::asio::io_service::post(). Chris@16: */ Chris@16: template Chris@16: BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler, Chris@16: void (boost::system::error_code)) Chris@16: async_wait(BOOST_ASIO_MOVE_ARG(WaitHandler) handler) Chris@16: { Chris@16: return this->get_service().async_wait(this->get_implementation(), Chris@16: BOOST_ASIO_MOVE_CAST(WaitHandler)(handler)); Chris@16: } 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_OBJECT_HANDLE) Chris@16: // || defined(GENERATING_DOCUMENTATION) Chris@16: Chris@16: #endif // BOOST_ASIO_WINDOWS_BASIC_OBJECT_HANDLE_HPP