00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ASIO_SOCKET_ACCEPTOR_SERVICE_HPP
00012 #define ASIO_SOCKET_ACCEPTOR_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/basic_socket.hpp"
00021 #include "asio/error.hpp"
00022 #include "asio/io_service.hpp"
00023 #include "asio/detail/epoll_reactor.hpp"
00024 #include "asio/detail/kqueue_reactor.hpp"
00025 #include "asio/detail/select_reactor.hpp"
00026 #include "asio/detail/service_base.hpp"
00027 #include "asio/detail/reactive_socket_service.hpp"
00028 #include "asio/detail/win_iocp_socket_service.hpp"
00029
00030 namespace asio {
00031
00033 template <typename Protocol>
00034 class socket_acceptor_service
00035 #if defined(GENERATING_DOCUMENTATION)
00036 : public asio::io_service::service
00037 #else
00038 : public asio::detail::service_base<socket_acceptor_service<Protocol> >
00039 #endif
00040 {
00041 public:
00042 #if defined(GENERATING_DOCUMENTATION)
00044 static asio::io_service::id id;
00045 #endif
00046
00048 typedef Protocol protocol_type;
00049
00051 typedef typename protocol_type::endpoint endpoint_type;
00052
00053 private:
00054
00055 #if defined(ASIO_HAS_IOCP)
00056 typedef detail::win_iocp_socket_service<Protocol> service_impl_type;
00057 #elif defined(ASIO_HAS_EPOLL)
00058 typedef detail::reactive_socket_service<
00059 Protocol, detail::epoll_reactor<false> > service_impl_type;
00060 #elif defined(ASIO_HAS_KQUEUE)
00061 typedef detail::reactive_socket_service<
00062 Protocol, detail::kqueue_reactor<false> > service_impl_type;
00063 #else
00064 typedef detail::reactive_socket_service<
00065 Protocol, detail::select_reactor<false> > service_impl_type;
00066 #endif
00067
00068 public:
00070 #if defined(GENERATING_DOCUMENTATION)
00071 typedef implementation_defined implementation_type;
00072 #else
00073 typedef typename service_impl_type::implementation_type implementation_type;
00074 #endif
00075
00077 #if defined(GENERATING_DOCUMENTATION)
00078 typedef implementation_defined native_type;
00079 #else
00080 typedef typename service_impl_type::native_type native_type;
00081 #endif
00082
00084 explicit socket_acceptor_service(asio::io_service& io_service)
00085 : asio::detail::service_base<
00086 socket_acceptor_service<Protocol> >(io_service),
00087 service_impl_(asio::use_service<service_impl_type>(io_service))
00088 {
00089 }
00090
00092 void shutdown_service()
00093 {
00094 }
00095
00097 void construct(implementation_type& impl)
00098 {
00099 service_impl_.construct(impl);
00100 }
00101
00103 void destroy(implementation_type& impl)
00104 {
00105 service_impl_.destroy(impl);
00106 }
00107
00109 asio::error_code open(implementation_type& impl,
00110 const protocol_type& protocol, asio::error_code& ec)
00111 {
00112 return service_impl_.open(impl, protocol, ec);
00113 }
00114
00116 asio::error_code assign(implementation_type& impl,
00117 const protocol_type& protocol, const native_type& native_acceptor,
00118 asio::error_code& ec)
00119 {
00120 return service_impl_.assign(impl, protocol, native_acceptor, ec);
00121 }
00122
00124 bool is_open(const implementation_type& impl) const
00125 {
00126 return service_impl_.is_open(impl);
00127 }
00128
00130 asio::error_code cancel(implementation_type& impl,
00131 asio::error_code& ec)
00132 {
00133 return service_impl_.cancel(impl, ec);
00134 }
00135
00137 asio::error_code bind(implementation_type& impl,
00138 const endpoint_type& endpoint, asio::error_code& ec)
00139 {
00140 return service_impl_.bind(impl, endpoint, ec);
00141 }
00142
00145 asio::error_code listen(implementation_type& impl, int backlog,
00146 asio::error_code& ec)
00147 {
00148 return service_impl_.listen(impl, backlog, ec);
00149 }
00150
00152 asio::error_code close(implementation_type& impl,
00153 asio::error_code& ec)
00154 {
00155 return service_impl_.close(impl, ec);
00156 }
00157
00159 native_type native(implementation_type& impl)
00160 {
00161 return service_impl_.native(impl);
00162 }
00163
00165 template <typename SettableSocketOption>
00166 asio::error_code set_option(implementation_type& impl,
00167 const SettableSocketOption& option, asio::error_code& ec)
00168 {
00169 return service_impl_.set_option(impl, option, ec);
00170 }
00171
00173 template <typename GettableSocketOption>
00174 asio::error_code get_option(const implementation_type& impl,
00175 GettableSocketOption& option, asio::error_code& ec) const
00176 {
00177 return service_impl_.get_option(impl, option, ec);
00178 }
00179
00181 template <typename IoControlCommand>
00182 asio::error_code io_control(implementation_type& impl,
00183 IoControlCommand& command, asio::error_code& ec)
00184 {
00185 return service_impl_.io_control(impl, command, ec);
00186 }
00187
00189 endpoint_type local_endpoint(const implementation_type& impl,
00190 asio::error_code& ec) const
00191 {
00192 return service_impl_.local_endpoint(impl, ec);
00193 }
00194
00196 template <typename SocketService>
00197 asio::error_code accept(implementation_type& impl,
00198 basic_socket<protocol_type, SocketService>& peer,
00199 endpoint_type* peer_endpoint, asio::error_code& ec)
00200 {
00201 return service_impl_.accept(impl, peer, peer_endpoint, ec);
00202 }
00203
00205 template <typename SocketService, typename AcceptHandler>
00206 void async_accept(implementation_type& impl,
00207 basic_socket<protocol_type, SocketService>& peer,
00208 endpoint_type* peer_endpoint, AcceptHandler handler)
00209 {
00210 service_impl_.async_accept(impl, peer, peer_endpoint, handler);
00211 }
00212
00213 private:
00214
00215 service_impl_type& service_impl_;
00216 };
00217
00218 }
00219
00220 #include "asio/detail/pop_options.hpp"
00221
00222 #endif // ASIO_SOCKET_ACCEPTOR_SERVICE_HPP