basic_handle.hpp
Go to the documentation of this file.
00001 //
00002 // basic_handle.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_WINDOWS_BASIC_HANDLE_HPP
00012 #define ASIO_WINDOWS_BASIC_HANDLE_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/detail/throw_error.hpp"
00027 
00028 namespace asio {
00029 namespace windows {
00030 
00032 
00040 template <typename HandleService>
00041 class basic_handle
00042   : public basic_io_object<HandleService>
00043 {
00044 public:
00046   typedef typename HandleService::native_type native_type;
00047 
00049   typedef basic_handle<HandleService> lowest_layer_type;
00050 
00052 
00058   explicit basic_handle(asio::io_service& io_service)
00059     : basic_io_object<HandleService>(io_service)
00060   {
00061   }
00062 
00064 
00074   basic_handle(asio::io_service& io_service,
00075       const native_type& native_handle)
00076     : basic_io_object<HandleService>(io_service)
00077   {
00078     asio::error_code ec;
00079     this->service.assign(this->implementation, native_handle, ec);
00080     asio::detail::throw_error(ec);
00081   }
00082 
00084 
00092   lowest_layer_type& lowest_layer()
00093   {
00094     return *this;
00095   }
00096 
00098   /*
00099    * This function opens the handle to hold an existing native handle.
00100    *
00101    * @param native_handle A native handle.
00102    *
00103    * @throws asio::system_error Thrown on failure.
00104    */
00105   void assign(const native_type& native_handle)
00106   {
00107     asio::error_code ec;
00108     this->service.assign(this->implementation, native_handle, ec);
00109     asio::detail::throw_error(ec);
00110   }
00111 
00113   /*
00114    * This function opens the handle to hold an existing native handle.
00115    *
00116    * @param native_handle A native handle.
00117    *
00118    * @param ec Set to indicate what error occurred, if any.
00119    */
00120   asio::error_code assign(const native_type& native_handle,
00121       asio::error_code& ec)
00122   {
00123     return this->service.assign(this->implementation, native_handle, ec);
00124   }
00125 
00127   bool is_open() const
00128   {
00129     return this->service.is_open(this->implementation);
00130   }
00131 
00133 
00140   void close()
00141   {
00142     asio::error_code ec;
00143     this->service.close(this->implementation, ec);
00144     asio::detail::throw_error(ec);
00145   }
00146 
00148 
00155   asio::error_code close(asio::error_code& ec)
00156   {
00157     return this->service.close(this->implementation, ec);
00158   }
00159 
00161 
00166   native_type native()
00167   {
00168     return this->service.native(this->implementation);
00169   }
00170 
00172 
00179   void cancel()
00180   {
00181     asio::error_code ec;
00182     this->service.cancel(this->implementation, ec);
00183     asio::detail::throw_error(ec);
00184   }
00185 
00187 
00194   asio::error_code cancel(asio::error_code& ec)
00195   {
00196     return this->service.cancel(this->implementation, ec);
00197   }
00198 
00199 protected:
00201   ~basic_handle()
00202   {
00203   }
00204 };
00205 
00206 } // namespace windows
00207 } // namespace asio
00208 
00209 #include "asio/detail/pop_options.hpp"
00210 
00211 #endif // ASIO_WINDOWS_BASIC_HANDLE_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


Castor
Author(s): Carpe Noctem
autogenerated on Fri Nov 8 2013 11:05:39