00001 // 00002 // strand.hpp 00003 // ~~~~~~~~~~ 00004 // 00005 // Copyright (c) 2003-2007 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_STRAND_HPP 00012 #define ASIO_STRAND_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/io_service.hpp" 00021 #include "asio/detail/strand_service.hpp" 00022 #include "asio/detail/wrapped_handler.hpp" 00023 00024 namespace asio { 00025 00027 00039 class io_service::strand 00040 { 00041 public: 00043 00049 explicit strand(asio::io_service& io_service) 00050 : service_(asio::use_service< 00051 asio::detail::strand_service>(io_service)) 00052 { 00053 service_.construct(impl_); 00054 } 00055 00057 ~strand() 00058 { 00059 service_.destroy(impl_); 00060 } 00061 00063 00070 asio::io_service& io_service() 00071 { 00072 return service_.io_service(); 00073 } 00074 00076 00094 template <typename Handler> 00095 void dispatch(Handler handler) 00096 { 00097 service_.dispatch(impl_, handler); 00098 } 00099 00102 00116 template <typename Handler> 00117 void post(Handler handler) 00118 { 00119 service_.post(impl_, handler); 00120 } 00121 00124 00143 template <typename Handler> 00144 #if defined(GENERATING_DOCUMENTATION) 00145 unspecified 00146 #else 00147 detail::wrapped_handler<strand, Handler> 00148 #endif 00149 wrap(Handler handler) 00150 { 00151 return detail::wrapped_handler<io_service::strand, Handler>(*this, handler); 00152 } 00153 00154 private: 00155 asio::detail::strand_service& service_; 00156 asio::detail::strand_service::implementation_type impl_; 00157 }; 00158 00160 typedef asio::io_service::strand strand; 00161 00162 } // namespace asio 00163 00164 #include "asio/detail/pop_options.hpp" 00165 00166 #endif // ASIO_STRAND_HPP
1.5.6