$search
00001 // 00002 // basic_descriptor.hpp 00003 // ~~~~~~~~~~~~~~~~~~~~ 00004 // 00005 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com) 00006 // 00007 // Distributed under the Boost Software License, Version 1.0. (See accompanying 00008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 00009 // 00010 00011 #ifndef ASIO_POSIX_BASIC_DESCRIPTOR_HPP 00012 #define ASIO_POSIX_BASIC_DESCRIPTOR_HPP 00013 00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 00015 # pragma once 00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 00017 00018 #include "asio/detail/push_options.hpp" 00019 00020 #include "asio/detail/push_options.hpp" 00021 #include <boost/config.hpp> 00022 #include "asio/detail/pop_options.hpp" 00023 00024 #include "asio/basic_io_object.hpp" 00025 #include "asio/error.hpp" 00026 #include "asio/posix/descriptor_base.hpp" 00027 #include "asio/detail/throw_error.hpp" 00028 00029 namespace asio { 00030 namespace posix { 00031 00033 00041 template <typename DescriptorService> 00042 class basic_descriptor 00043 : public basic_io_object<DescriptorService>, 00044 public descriptor_base 00045 { 00046 public: 00048 typedef typename DescriptorService::native_type native_type; 00049 00051 typedef basic_descriptor<DescriptorService> lowest_layer_type; 00052 00054 00061 explicit basic_descriptor(asio::io_service& io_service) 00062 : basic_io_object<DescriptorService>(io_service) 00063 { 00064 } 00065 00067 00079 basic_descriptor(asio::io_service& io_service, 00080 const native_type& native_descriptor) 00081 : basic_io_object<DescriptorService>(io_service) 00082 { 00083 asio::error_code ec; 00084 this->service.assign(this->implementation, native_descriptor, ec); 00085 asio::detail::throw_error(ec); 00086 } 00087 00089 00097 lowest_layer_type& lowest_layer() 00098 { 00099 return *this; 00100 } 00101 00103 /* 00104 * This function opens the descriptor to hold an existing native descriptor. 00105 * 00106 * @param native_descriptor A native descriptor. 00107 * 00108 * @throws asio::system_error Thrown on failure. 00109 */ 00110 void assign(const native_type& native_descriptor) 00111 { 00112 asio::error_code ec; 00113 this->service.assign(this->implementation, native_descriptor, ec); 00114 asio::detail::throw_error(ec); 00115 } 00116 00118 /* 00119 * This function opens the descriptor to hold an existing native descriptor. 00120 * 00121 * @param native_descriptor A native descriptor. 00122 * 00123 * @param ec Set to indicate what error occurred, if any. 00124 */ 00125 asio::error_code assign(const native_type& native_descriptor, 00126 asio::error_code& ec) 00127 { 00128 return this->service.assign(this->implementation, native_descriptor, ec); 00129 } 00130 00132 bool is_open() const 00133 { 00134 return this->service.is_open(this->implementation); 00135 } 00136 00138 00145 void close() 00146 { 00147 asio::error_code ec; 00148 this->service.close(this->implementation, ec); 00149 asio::detail::throw_error(ec); 00150 } 00151 00153 00160 asio::error_code close(asio::error_code& ec) 00161 { 00162 return this->service.close(this->implementation, ec); 00163 } 00164 00166 00171 native_type native() 00172 { 00173 return this->service.native(this->implementation); 00174 } 00175 00177 00184 void cancel() 00185 { 00186 asio::error_code ec; 00187 this->service.cancel(this->implementation, ec); 00188 asio::detail::throw_error(ec); 00189 } 00190 00192 00199 asio::error_code cancel(asio::error_code& ec) 00200 { 00201 return this->service.cancel(this->implementation, ec); 00202 } 00203 00205 00226 template <typename IoControlCommand> 00227 void io_control(IoControlCommand& command) 00228 { 00229 asio::error_code ec; 00230 this->service.io_control(this->implementation, command, ec); 00231 asio::detail::throw_error(ec); 00232 } 00233 00235 00261 template <typename IoControlCommand> 00262 asio::error_code io_control(IoControlCommand& command, 00263 asio::error_code& ec) 00264 { 00265 return this->service.io_control(this->implementation, command, ec); 00266 } 00267 00268 protected: 00270 ~basic_descriptor() 00271 { 00272 } 00273 }; 00274 00275 } // namespace posix 00276 } // namespace asio 00277 00278 #include "asio/detail/pop_options.hpp" 00279 00280 #endif // ASIO_POSIX_BASIC_DESCRIPTOR_HPP