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)
00047
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 #elif defined(ASIO_HAS_DEV_POLL)
00068 typedef detail::reactive_socket_service<
00069 Protocol, detail::dev_poll_reactor<false> > service_impl_type;
00070 #else
00071 typedef detail::reactive_socket_service<
00072 Protocol, detail::select_reactor<false> > service_impl_type;
00073 #endif
00074
00075 public:
00077 #if defined(GENERATING_DOCUMENTATION)
00078 typedef implementation_defined implementation_type;
00079 #else
00080 typedef typename service_impl_type::implementation_type implementation_type;
00081 #endif
00082
00084 #if defined(GENERATING_DOCUMENTATION)
00085 typedef implementation_defined native_type;
00086 #else
00087 typedef typename service_impl_type::native_type native_type;
00088 #endif
00089
00091 explicit stream_socket_service(asio::io_service& io_service)
00092 : asio::detail::service_base<
00093 stream_socket_service<Protocol> >(io_service),
00094 service_impl_(asio::use_service<service_impl_type>(io_service))
00095 {
00096 }
00097
00099 void shutdown_service()
00100 {
00101 }
00102
00104 void construct(implementation_type& impl)
00105 {
00106 service_impl_.construct(impl);
00107 }
00108
00110 void destroy(implementation_type& impl)
00111 {
00112 service_impl_.destroy(impl);
00113 }
00114
00116 asio::error_code open(implementation_type& impl,
00117 const protocol_type& protocol, asio::error_code& ec)
00118 {
00119 if (protocol.type() == SOCK_STREAM)
00120 service_impl_.open(impl, protocol, ec);
00121 else
00122 ec = asio::error::invalid_argument;
00123 return ec;
00124 }
00125
00127 asio::error_code assign(implementation_type& impl,
00128 const protocol_type& protocol, const native_type& native_socket,
00129 asio::error_code& ec)
00130 {
00131 return service_impl_.assign(impl, protocol, native_socket, ec);
00132 }
00133
00135 bool is_open(const implementation_type& impl) const
00136 {
00137 return service_impl_.is_open(impl);
00138 }
00139
00141 asio::error_code close(implementation_type& impl,
00142 asio::error_code& ec)
00143 {
00144 return service_impl_.close(impl, ec);
00145 }
00146
00148 native_type native(implementation_type& impl)
00149 {
00150 return service_impl_.native(impl);
00151 }
00152
00154 asio::error_code cancel(implementation_type& impl,
00155 asio::error_code& ec)
00156 {
00157 return service_impl_.cancel(impl, ec);
00158 }
00159
00161 bool at_mark(const implementation_type& impl,
00162 asio::error_code& ec) const
00163 {
00164 return service_impl_.at_mark(impl, ec);
00165 }
00166
00168 std::size_t available(const implementation_type& impl,
00169 asio::error_code& ec) const
00170 {
00171 return service_impl_.available(impl, ec);
00172 }
00173
00175 asio::error_code bind(implementation_type& impl,
00176 const endpoint_type& endpoint, asio::error_code& ec)
00177 {
00178 return service_impl_.bind(impl, endpoint, ec);
00179 }
00180
00182 asio::error_code connect(implementation_type& impl,
00183 const endpoint_type& peer_endpoint, asio::error_code& ec)
00184 {
00185 return service_impl_.connect(impl, peer_endpoint, ec);
00186 }
00187
00189 template <typename ConnectHandler>
00190 void async_connect(implementation_type& impl,
00191 const endpoint_type& peer_endpoint, ConnectHandler handler)
00192 {
00193 service_impl_.async_connect(impl, peer_endpoint, handler);
00194 }
00195
00197 template <typename SettableSocketOption>
00198 asio::error_code set_option(implementation_type& impl,
00199 const SettableSocketOption& option, asio::error_code& ec)
00200 {
00201 return service_impl_.set_option(impl, option, ec);
00202 }
00203
00205 template <typename GettableSocketOption>
00206 asio::error_code get_option(const implementation_type& impl,
00207 GettableSocketOption& option, asio::error_code& ec) const
00208 {
00209 return service_impl_.get_option(impl, option, ec);
00210 }
00211
00213 template <typename IoControlCommand>
00214 asio::error_code io_control(implementation_type& impl,
00215 IoControlCommand& command, asio::error_code& ec)
00216 {
00217 return service_impl_.io_control(impl, command, ec);
00218 }
00219
00221 endpoint_type local_endpoint(const implementation_type& impl,
00222 asio::error_code& ec) const
00223 {
00224 return service_impl_.local_endpoint(impl, ec);
00225 }
00226
00228 endpoint_type remote_endpoint(const implementation_type& impl,
00229 asio::error_code& ec) const
00230 {
00231 return service_impl_.remote_endpoint(impl, ec);
00232 }
00233
00235 asio::error_code shutdown(implementation_type& impl,
00236 socket_base::shutdown_type what, asio::error_code& ec)
00237 {
00238 return service_impl_.shutdown(impl, what, ec);
00239 }
00240
00242 template <typename ConstBufferSequence>
00243 std::size_t send(implementation_type& impl,
00244 const ConstBufferSequence& buffers,
00245 socket_base::message_flags flags, asio::error_code& ec)
00246 {
00247 return service_impl_.send(impl, buffers, flags, ec);
00248 }
00249
00251 template <typename ConstBufferSequence, typename WriteHandler>
00252 void async_send(implementation_type& impl,
00253 const ConstBufferSequence& buffers,
00254 socket_base::message_flags flags, WriteHandler handler)
00255 {
00256 service_impl_.async_send(impl, buffers, flags, handler);
00257 }
00258
00260 template <typename MutableBufferSequence>
00261 std::size_t receive(implementation_type& impl,
00262 const MutableBufferSequence& buffers,
00263 socket_base::message_flags flags, asio::error_code& ec)
00264 {
00265 return service_impl_.receive(impl, buffers, flags, ec);
00266 }
00267
00269 template <typename MutableBufferSequence, typename ReadHandler>
00270 void async_receive(implementation_type& impl,
00271 const MutableBufferSequence& buffers,
00272 socket_base::message_flags flags, ReadHandler handler)
00273 {
00274 service_impl_.async_receive(impl, buffers, flags, handler);
00275 }
00276
00277 private:
00278
00279 service_impl_type& service_impl_;
00280 };
00281
00282 }
00283
00284 #include "asio/detail/pop_options.hpp"
00285
00286 #endif // ASIO_STREAM_SOCKET_SERVICE_HPP