Chris@16: // Chris@16: // posix/stream_descriptor_service.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_POSIX_STREAM_DESCRIPTOR_SERVICE_HPP Chris@16: #define BOOST_ASIO_POSIX_STREAM_DESCRIPTOR_SERVICE_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_POSIX_STREAM_DESCRIPTOR) \ Chris@16: || defined(GENERATING_DOCUMENTATION) Chris@16: Chris@16: #include 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 posix { Chris@16: Chris@16: /// Default service implementation for a stream descriptor. Chris@16: class stream_descriptor_service Chris@16: #if defined(GENERATING_DOCUMENTATION) Chris@16: : public boost::asio::io_service::service Chris@16: #else Chris@16: : public boost::asio::detail::service_base Chris@16: #endif Chris@16: { Chris@16: public: Chris@16: #if defined(GENERATING_DOCUMENTATION) Chris@16: /// The unique service identifier. Chris@16: static boost::asio::io_service::id id; Chris@16: #endif Chris@16: Chris@16: private: Chris@16: // The type of the platform-specific implementation. Chris@16: typedef detail::reactive_descriptor_service service_impl_type; Chris@16: Chris@16: public: Chris@16: /// The type of a stream descriptor implementation. Chris@16: #if defined(GENERATING_DOCUMENTATION) Chris@16: typedef implementation_defined implementation_type; Chris@16: #else Chris@16: typedef service_impl_type::implementation_type implementation_type; Chris@16: #endif Chris@16: Chris@16: /// (Deprecated: Use native_handle_type.) The native descriptor type. Chris@16: #if defined(GENERATING_DOCUMENTATION) Chris@16: typedef implementation_defined native_type; Chris@16: #else Chris@16: typedef service_impl_type::native_handle_type native_type; Chris@16: #endif Chris@16: Chris@16: /// The native descriptor type. Chris@16: #if defined(GENERATING_DOCUMENTATION) Chris@16: typedef implementation_defined native_handle_type; Chris@16: #else Chris@16: typedef service_impl_type::native_handle_type native_handle_type; Chris@16: #endif Chris@16: Chris@16: /// Construct a new stream descriptor service for the specified io_service. Chris@16: explicit stream_descriptor_service(boost::asio::io_service& io_service) Chris@16: : boost::asio::detail::service_base(io_service), Chris@16: service_impl_(io_service) Chris@16: { Chris@16: } Chris@16: Chris@16: /// Construct a new stream descriptor implementation. Chris@16: void construct(implementation_type& impl) Chris@16: { Chris@16: service_impl_.construct(impl); Chris@16: } Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) Chris@16: /// Move-construct a new stream descriptor implementation. Chris@16: void move_construct(implementation_type& impl, Chris@16: implementation_type& other_impl) Chris@16: { Chris@16: service_impl_.move_construct(impl, other_impl); Chris@16: } Chris@16: Chris@16: /// Move-assign from another stream descriptor implementation. Chris@16: void move_assign(implementation_type& impl, Chris@16: stream_descriptor_service& other_service, Chris@16: implementation_type& other_impl) Chris@16: { Chris@16: service_impl_.move_assign(impl, other_service.service_impl_, other_impl); Chris@16: } Chris@16: #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) Chris@16: Chris@16: /// Destroy a stream descriptor implementation. Chris@16: void destroy(implementation_type& impl) Chris@16: { Chris@16: service_impl_.destroy(impl); Chris@16: } Chris@16: Chris@16: /// Assign an existing native descriptor to a stream descriptor. Chris@16: boost::system::error_code assign(implementation_type& impl, Chris@16: const native_handle_type& native_descriptor, Chris@16: boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.assign(impl, native_descriptor, ec); Chris@16: } Chris@16: Chris@16: /// Determine whether the descriptor is open. Chris@16: bool is_open(const implementation_type& impl) const Chris@16: { Chris@16: return service_impl_.is_open(impl); Chris@16: } Chris@16: Chris@16: /// Close a stream descriptor implementation. Chris@16: boost::system::error_code close(implementation_type& impl, Chris@16: boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.close(impl, ec); Chris@16: } Chris@16: Chris@16: /// (Deprecated: Use native_handle().) Get the native descriptor Chris@16: /// implementation. Chris@16: native_type native(implementation_type& impl) Chris@16: { Chris@16: return service_impl_.native_handle(impl); Chris@16: } Chris@16: Chris@16: /// Get the native descriptor implementation. Chris@16: native_handle_type native_handle(implementation_type& impl) Chris@16: { Chris@16: return service_impl_.native_handle(impl); Chris@16: } Chris@16: Chris@16: /// Release ownership of the native descriptor implementation. Chris@16: native_handle_type release(implementation_type& impl) Chris@16: { Chris@16: return service_impl_.release(impl); Chris@16: } Chris@16: Chris@16: /// Cancel all asynchronous operations associated with the descriptor. Chris@16: boost::system::error_code cancel(implementation_type& impl, Chris@16: boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.cancel(impl, ec); Chris@16: } Chris@16: Chris@16: /// Perform an IO control command on the descriptor. Chris@16: template Chris@16: boost::system::error_code io_control(implementation_type& impl, Chris@16: IoControlCommand& command, boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.io_control(impl, command, ec); Chris@16: } Chris@16: Chris@16: /// Gets the non-blocking mode of the descriptor. Chris@16: bool non_blocking(const implementation_type& impl) const Chris@16: { Chris@16: return service_impl_.non_blocking(impl); Chris@16: } Chris@16: Chris@16: /// Sets the non-blocking mode of the descriptor. Chris@16: boost::system::error_code non_blocking(implementation_type& impl, Chris@16: bool mode, boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.non_blocking(impl, mode, ec); Chris@16: } Chris@16: Chris@16: /// Gets the non-blocking mode of the native descriptor implementation. Chris@16: bool native_non_blocking(const implementation_type& impl) const Chris@16: { Chris@16: return service_impl_.native_non_blocking(impl); Chris@16: } Chris@16: Chris@16: /// Sets the non-blocking mode of the native descriptor implementation. Chris@16: boost::system::error_code native_non_blocking(implementation_type& impl, Chris@16: bool mode, boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.native_non_blocking(impl, mode, ec); Chris@16: } Chris@16: Chris@16: /// Write the given data to the stream. Chris@16: template Chris@16: std::size_t write_some(implementation_type& impl, Chris@16: const ConstBufferSequence& buffers, boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.write_some(impl, buffers, ec); Chris@16: } Chris@16: Chris@16: /// Start an asynchronous write. Chris@16: template Chris@16: BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, Chris@16: void (boost::system::error_code, std::size_t)) Chris@16: async_write_some(implementation_type& impl, Chris@16: const ConstBufferSequence& buffers, Chris@16: BOOST_ASIO_MOVE_ARG(WriteHandler) handler) Chris@16: { Chris@16: boost::asio::detail::async_result_init< Chris@16: WriteHandler, void (boost::system::error_code, std::size_t)> init( Chris@16: BOOST_ASIO_MOVE_CAST(WriteHandler)(handler)); Chris@16: Chris@16: service_impl_.async_write_some(impl, buffers, init.handler); Chris@16: Chris@16: return init.result.get(); Chris@16: } Chris@16: Chris@16: /// Read some data from the stream. Chris@16: template Chris@16: std::size_t read_some(implementation_type& impl, Chris@16: const MutableBufferSequence& buffers, boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.read_some(impl, buffers, ec); Chris@16: } Chris@16: Chris@16: /// Start an asynchronous read. Chris@16: template Chris@16: BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, Chris@16: void (boost::system::error_code, std::size_t)) Chris@16: async_read_some(implementation_type& impl, Chris@16: const MutableBufferSequence& buffers, Chris@16: BOOST_ASIO_MOVE_ARG(ReadHandler) handler) Chris@16: { Chris@16: boost::asio::detail::async_result_init< Chris@16: ReadHandler, void (boost::system::error_code, std::size_t)> init( Chris@16: BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)); Chris@16: Chris@16: service_impl_.async_read_some(impl, buffers, init.handler); Chris@16: Chris@16: return init.result.get(); Chris@16: } Chris@16: Chris@16: private: Chris@16: // Destroy all user-defined handler objects owned by the service. Chris@16: void shutdown_service() Chris@16: { Chris@16: service_impl_.shutdown_service(); Chris@16: } Chris@16: Chris@16: // The platform-specific implementation. Chris@16: service_impl_type service_impl_; Chris@16: }; Chris@16: Chris@16: } // namespace posix Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR) Chris@16: // || defined(GENERATING_DOCUMENTATION) Chris@16: Chris@16: #endif // BOOST_ASIO_POSIX_STREAM_DESCRIPTOR_SERVICE_HPP