00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ASIO_STREAM_SOCKET_SERVICE_HPP
00012 #define ASIO_STREAM_SOCKET_SERVICE_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 <cstddef>
00022 #include <boost/config.hpp>
00023 #include "asio/detail/pop_options.hpp"
00024
00025 #include "asio/error.hpp"
00026 #include "asio/io_service.hpp"
00027 #include "asio/detail/epoll_reactor.hpp"
00028 #include "asio/detail/kqueue_reactor.hpp"
00029 #include "asio/detail/select_reactor.hpp"
00030 #include "asio/detail/service_base.hpp"
00031 #include "asio/detail/win_iocp_socket_service.hpp"
00032 #include "asio/detail/reactive_socket_service.hpp"
00033
00034 namespace asio {
00035
00037 template <typename Protocol>
00038 class stream_socket_service
00039 #if defined(GENERATING_DOCUMENTATION)
00040 : public asio::io_service::service
00041 #else
00042 : public asio::detail::service_base<stream_socket_service<Protocol> >
00043 #endif
00044 {
00045 public:
00046 #if defined(GENERATING_DOCUMENTATION)
00048 static asio::io_service::id id;
00049 #endif
00050
00052 typedef Protocol protocol_type;
00053
00055 typedef typename Protocol::endpoint endpoint_type;
00056
00057 private:
00058
00059 #if defined(ASIO_HAS_IOCP)
00060 typedef detail::win_iocp_socket_service<Protocol> service_impl_type;
00061 #elif defined(ASIO_HAS_EPOLL)
00062 typedef detail::reactive_socket_service<
00063 Protocol, detail::epoll_reactor<false> > service_impl_type;
00064 #elif defined(ASIO_HAS_KQUEUE)
00065 typedef detail::reactive_socket_service<
00066 Protocol, detail::kqueue_reactor<false> > service_impl_type;
00067 #else
00068 typedef detail::reactive_socket_service<
00069 Protocol, detail::select_reactor<false> > service_impl_type;
00070 #endif
00071
00072 public:
00074 #if defined(GENERATING_DOCUMENTATION)
00075 typedef implementation_defined implementation_type;
00076 #else
00077 typedef typename service_impl_type::implementation_type implementation_type;
00078 #endif
00079
00081 #if defined(GENERATING_DOCUMENTATION)
00082 typedef implementation_defined native_type;
00083 #else
00084 typedef typename service_impl_type::native_type native_type;
00085 #endif
00086
00088 explicit stream_socket_service(asio::io_service& io_service)
00089 : asio::detail::service_base<
00090 stream_socket_service<Protocol> >(io_service),
00091 service_impl_(asio::use_service<service_impl_type>(io_service))
00092 {
00093 }
00094
00096 void shutdown_service()
00097 {
00098 }
00099
00101 void construct(implementation_type& impl)
00102 {
00103 service_impl_.construct(impl);
00104 }
00105
00107 void destroy(implementation_type& impl)
00108 {
00109 service_impl_.destroy(impl);
00110 }
00111
00113 asio::error_code open(implementation_type& impl,
00114 const protocol_type& protocol, asio::error_code& ec)
00115 {
00116 if (protocol.type() == SOCK_STREAM)
00117 service_impl_.open(impl, protocol, ec);
00118 else
00119 ec = asio::error::invalid_argument;
00120 return ec;
00121 }
00122
00124 asio::error_code assign(implementation_type& impl,
00125 const protocol_type& protocol, const native_type& native_socket,
00126 asio::error_code& ec)
00127 {
00128 return service_impl_.assign(impl, protocol, native_socket, ec);
00129 }
00130
00132 bool is_open(const implementation_type& impl) const
00133 {
00134 return service_impl_.is_open(impl);
00135 }
00136
00138 asio::error_code close(implementation_type& impl,
00139 asio::error_code& ec)
00140 {
00141 return service_impl_.close(impl, ec);
00142 }
00143
00145 native_type native(implementation_type& impl)
00146 {
00147 return service_impl_.native(impl);
00148 }
00149
00151 asio::error_code cancel(implementation_type& impl,
00152 asio::error_code& ec)
00153 {
00154 return service_impl_.cancel(impl, ec);
00155 }
00156
00158 bool at_mark(const implementation_type& impl,
00159 asio::error_code& ec) const
00160 {
00161 return service_impl_.at_mark(impl, ec);
00162 }
00163
00165 std::size_t available(const implementation_type& impl,
00166 asio::error_code& ec) const
00167 {
00168 return service_impl_.available(impl, ec);
00169 }
00170
00172 asio::error_code bind(implementation_type& impl,
00173 const endpoint_type& endpoint, asio::error_code& ec)
00174 {
00175 return service_impl_.bind(impl, endpoint, ec);
00176 }
00177
00179 asio::error_code connect(implementation_type& impl,
00180 const endpoint_type& peer_endpoint, asio::error_code& ec)
00181 {
00182 return service_impl_.connect(impl, peer_endpoint, ec);
00183 }
00184
00186 template <typename ConnectHandler>
00187 void async_connect(implementation_type& impl,
00188 const endpoint_type& peer_endpoint, ConnectHandler handler)
00189 {
00190 service_impl_.async_connect(impl, peer_endpoint, handler);
00191 }
00192
00194 template <typename SettableSocketOption>
00195 asio::error_code set_option(implementation_type& impl,
00196 const SettableSocketOption& option, asio::error_code& ec)
00197 {
00198 return service_impl_.set_option(impl, option, ec);
00199 }
00200
00202 template <typename GettableSocketOption>
00203 asio::error_code get_option(const implementation_type& impl,
00204 GettableSocketOption& option, asio::error_code& ec) const
00205 {
00206 return service_impl_.get_option(impl, option, ec);
00207 }
00208
00210 template <typename IoControlCommand>
00211 asio::error_code io_control(implementation_type& impl,
00212 IoControlCommand& command, asio::error_code& ec)
00213 {
00214 return service_impl_.io_control(impl, command, ec);
00215 }
00216
00218 endpoint_type local_endpoint(const implementation_type& impl,
00219 asio::error_code& ec) const
00220 {
00221 return service_impl_.local_endpoint(impl, ec);
00222 }
00223
00225 endpoint_type remote_endpoint(const implementation_type& impl,
00226 asio::error_code& ec) const
00227 {
00228 return service_impl_.remote_endpoint(impl, ec);
00229 }
00230
00232 asio::error_code shutdown(implementation_type& impl,
00233 socket_base::shutdown_type what, asio::error_code& ec)
00234 {
00235 return service_impl_.shutdown(impl, what, ec);
00236 }
00237
00239 template <typename ConstBufferSequence>
00240 std::size_t send(implementation_type& impl,
00241 const ConstBufferSequence& buffers,
00242 socket_base::message_flags flags, asio::error_code& ec)
00243 {
00244 return service_impl_.send(impl, buffers, flags, ec);
00245 }
00246
00248 template <typename ConstBufferSequence, typename WriteHandler>
00249 void async_send(implementation_type& impl,
00250 const ConstBufferSequence& buffers,
00251 socket_base::message_flags flags, WriteHandler handler)
00252 {
00253 service_impl_.async_send(impl, buffers, flags, handler);
00254 }
00255
00257 template <typename MutableBufferSequence>
00258 std::size_t receive(implementation_type& impl,
00259 const MutableBufferSequence& buffers,
00260 socket_base::message_flags flags, asio::error_code& ec)
00261 {
00262 return service_impl_.receive(impl, buffers, flags, ec);
00263 }
00264
00266 template <typename MutableBufferSequence, typename ReadHandler>
00267 void async_receive(implementation_type& impl,
00268 const MutableBufferSequence& buffers,
00269 socket_base::message_flags flags, ReadHandler handler)
00270 {
00271 service_impl_.async_receive(impl, buffers, flags, handler);
00272 }
00273
00274 private:
00275
00276 service_impl_type& service_impl_;
00277 };
00278
00279 }
00280
00281 #include "asio/detail/pop_options.hpp"
00282
00283 #endif // ASIO_STREAM_SOCKET_SERVICE_HPP