PageRenderTime 18ms CodeModel.GetById 1ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

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