/Src/Dependencies/Boost/boost/asio/socket_acceptor_service.hpp

http://hadesmem.googlecode.com/ · C++ Header · 277 lines · 191 code · 42 blank · 44 comment · 2 complexity · 420bcf9714083c9144ddc3a3d1002c0c MD5 · raw file

  1. //
  2. // socket_acceptor_service.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2011 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_SOCKET_ACCEPTOR_SERVICE_HPP
  11. #define BOOST_ASIO_SOCKET_ACCEPTOR_SERVICE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/basic_socket.hpp>
  17. #include <boost/asio/error.hpp>
  18. #include <boost/asio/io_service.hpp>
  19. #if defined(BOOST_ASIO_HAS_IOCP)
  20. # include <boost/asio/detail/win_iocp_socket_service.hpp>
  21. #else
  22. # include <boost/asio/detail/reactive_socket_service.hpp>
  23. #endif
  24. #include <boost/asio/detail/push_options.hpp>
  25. namespace boost {
  26. namespace asio {
  27. /// Default service implementation for a socket acceptor.
  28. template <typename Protocol>
  29. class socket_acceptor_service
  30. #if defined(GENERATING_DOCUMENTATION)
  31. : public boost::asio::io_service::service
  32. #else
  33. : public boost::asio::detail::service_base<socket_acceptor_service<Protocol> >
  34. #endif
  35. {
  36. public:
  37. #if defined(GENERATING_DOCUMENTATION)
  38. /// The unique service identifier.
  39. static boost::asio::io_service::id id;
  40. #endif
  41. /// The protocol type.
  42. typedef Protocol protocol_type;
  43. /// The endpoint type.
  44. typedef typename protocol_type::endpoint endpoint_type;
  45. private:
  46. // The type of the platform-specific implementation.
  47. #if defined(BOOST_ASIO_HAS_IOCP)
  48. typedef detail::win_iocp_socket_service<Protocol> service_impl_type;
  49. #else
  50. typedef detail::reactive_socket_service<Protocol> service_impl_type;
  51. #endif
  52. public:
  53. /// The native type of the socket acceptor.
  54. #if defined(GENERATING_DOCUMENTATION)
  55. typedef implementation_defined implementation_type;
  56. #else
  57. typedef typename service_impl_type::implementation_type implementation_type;
  58. #endif
  59. /// (Deprecated: Use native_handle_type.) The native acceptor type.
  60. #if defined(GENERATING_DOCUMENTATION)
  61. typedef implementation_defined native_type;
  62. #else
  63. typedef typename service_impl_type::native_handle_type native_type;
  64. #endif
  65. /// The native acceptor type.
  66. #if defined(GENERATING_DOCUMENTATION)
  67. typedef implementation_defined native_handle_type;
  68. #else
  69. typedef typename service_impl_type::native_handle_type native_handle_type;
  70. #endif
  71. /// Construct a new socket acceptor service for the specified io_service.
  72. explicit socket_acceptor_service(boost::asio::io_service& io_service)
  73. : boost::asio::detail::service_base<
  74. socket_acceptor_service<Protocol> >(io_service),
  75. service_impl_(io_service)
  76. {
  77. }
  78. /// Construct a new socket acceptor implementation.
  79. void construct(implementation_type& impl)
  80. {
  81. service_impl_.construct(impl);
  82. }
  83. #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  84. /// Move-construct a new socket acceptor implementation.
  85. void move_construct(implementation_type& impl,
  86. implementation_type& other_impl)
  87. {
  88. service_impl_.move_construct(impl, other_impl);
  89. }
  90. /// Move-assign from another socket acceptor implementation.
  91. void move_assign(implementation_type& impl,
  92. socket_acceptor_service& other_service,
  93. implementation_type& other_impl)
  94. {
  95. service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
  96. }
  97. #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  98. /// Destroy a socket acceptor implementation.
  99. void destroy(implementation_type& impl)
  100. {
  101. service_impl_.destroy(impl);
  102. }
  103. /// Open a new socket acceptor implementation.
  104. boost::system::error_code open(implementation_type& impl,
  105. const protocol_type& protocol, boost::system::error_code& ec)
  106. {
  107. return service_impl_.open(impl, protocol, ec);
  108. }
  109. /// Assign an existing native acceptor to a socket acceptor.
  110. boost::system::error_code assign(implementation_type& impl,
  111. const protocol_type& protocol, const native_handle_type& native_acceptor,
  112. boost::system::error_code& ec)
  113. {
  114. return service_impl_.assign(impl, protocol, native_acceptor, ec);
  115. }
  116. /// Determine whether the acceptor is open.
  117. bool is_open(const implementation_type& impl) const
  118. {
  119. return service_impl_.is_open(impl);
  120. }
  121. /// Cancel all asynchronous operations associated with the acceptor.
  122. boost::system::error_code cancel(implementation_type& impl,
  123. boost::system::error_code& ec)
  124. {
  125. return service_impl_.cancel(impl, ec);
  126. }
  127. /// Bind the socket acceptor to the specified local endpoint.
  128. boost::system::error_code bind(implementation_type& impl,
  129. const endpoint_type& endpoint, boost::system::error_code& ec)
  130. {
  131. return service_impl_.bind(impl, endpoint, ec);
  132. }
  133. /// Place the socket acceptor into the state where it will listen for new
  134. /// connections.
  135. boost::system::error_code listen(implementation_type& impl, int backlog,
  136. boost::system::error_code& ec)
  137. {
  138. return service_impl_.listen(impl, backlog, ec);
  139. }
  140. /// Close a socket acceptor implementation.
  141. boost::system::error_code close(implementation_type& impl,
  142. boost::system::error_code& ec)
  143. {
  144. return service_impl_.close(impl, ec);
  145. }
  146. /// (Deprecated: Use native_handle().) Get the native acceptor implementation.
  147. native_type native(implementation_type& impl)
  148. {
  149. return service_impl_.native_handle(impl);
  150. }
  151. /// Get the native acceptor implementation.
  152. native_handle_type native_handle(implementation_type& impl)
  153. {
  154. return service_impl_.native_handle(impl);
  155. }
  156. /// Set a socket option.
  157. template <typename SettableSocketOption>
  158. boost::system::error_code set_option(implementation_type& impl,
  159. const SettableSocketOption& option, boost::system::error_code& ec)
  160. {
  161. return service_impl_.set_option(impl, option, ec);
  162. }
  163. /// Get a socket option.
  164. template <typename GettableSocketOption>
  165. boost::system::error_code get_option(const implementation_type& impl,
  166. GettableSocketOption& option, boost::system::error_code& ec) const
  167. {
  168. return service_impl_.get_option(impl, option, ec);
  169. }
  170. /// Perform an IO control command on the socket.
  171. template <typename IoControlCommand>
  172. boost::system::error_code io_control(implementation_type& impl,
  173. IoControlCommand& command, boost::system::error_code& ec)
  174. {
  175. return service_impl_.io_control(impl, command, ec);
  176. }
  177. /// Gets the non-blocking mode of the acceptor.
  178. bool non_blocking(const implementation_type& impl) const
  179. {
  180. return service_impl_.non_blocking(impl);
  181. }
  182. /// Sets the non-blocking mode of the acceptor.
  183. boost::system::error_code non_blocking(implementation_type& impl,
  184. bool mode, boost::system::error_code& ec)
  185. {
  186. return service_impl_.non_blocking(impl, mode, ec);
  187. }
  188. /// Gets the non-blocking mode of the native acceptor implementation.
  189. bool native_non_blocking(const implementation_type& impl) const
  190. {
  191. return service_impl_.native_non_blocking(impl);
  192. }
  193. /// Sets the non-blocking mode of the native acceptor implementation.
  194. boost::system::error_code native_non_blocking(implementation_type& impl,
  195. bool mode, boost::system::error_code& ec)
  196. {
  197. return service_impl_.native_non_blocking(impl, mode, ec);
  198. }
  199. /// Get the local endpoint.
  200. endpoint_type local_endpoint(const implementation_type& impl,
  201. boost::system::error_code& ec) const
  202. {
  203. return service_impl_.local_endpoint(impl, ec);
  204. }
  205. /// Accept a new connection.
  206. template <typename SocketService>
  207. boost::system::error_code accept(implementation_type& impl,
  208. basic_socket<protocol_type, SocketService>& peer,
  209. endpoint_type* peer_endpoint, boost::system::error_code& ec)
  210. {
  211. return service_impl_.accept(impl, peer, peer_endpoint, ec);
  212. }
  213. /// Start an asynchronous accept.
  214. template <typename SocketService, typename AcceptHandler>
  215. void async_accept(implementation_type& impl,
  216. basic_socket<protocol_type, SocketService>& peer,
  217. endpoint_type* peer_endpoint,
  218. BOOST_ASIO_MOVE_ARG(AcceptHandler) handler)
  219. {
  220. service_impl_.async_accept(impl, peer, peer_endpoint,
  221. BOOST_ASIO_MOVE_CAST(AcceptHandler)(handler));
  222. }
  223. private:
  224. // Destroy all user-defined handler objects owned by the service.
  225. void shutdown_service()
  226. {
  227. service_impl_.shutdown_service();
  228. }
  229. // The platform-specific implementation.
  230. service_impl_type service_impl_;
  231. };
  232. } // namespace asio
  233. } // namespace boost
  234. #include <boost/asio/detail/pop_options.hpp>
  235. #endif // BOOST_ASIO_SOCKET_ACCEPTOR_SERVICE_HPP