Realistic 3D camera system
3D camera system components
socket_acceptor_service.hpp
Go to the documentation of this file.
1 //
2 // socket_acceptor_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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 ASIO_SOCKET_ACCEPTOR_SERVICE_HPP
12 #define 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 "asio/detail/config.hpp"
19 #include "asio/basic_socket.hpp"
21 #include "asio/error.hpp"
22 #include "asio/io_service.hpp"
23 
24 #if defined(ASIO_WINDOWS_RUNTIME)
26 #elif defined(ASIO_HAS_IOCP)
28 #else
30 #endif
31 
33 
34 namespace asio {
35 
37 template <typename Protocol>
39 #if defined(GENERATING_DOCUMENTATION)
41 #else
42  : public asio::detail::service_base<socket_acceptor_service<Protocol> >
43 #endif
44 {
45 public:
46 #if defined(GENERATING_DOCUMENTATION)
47  static asio::io_service::id id;
49 #endif
50 
52  typedef Protocol protocol_type;
53 
55  typedef typename protocol_type::endpoint endpoint_type;
56 
57 private:
58  // The type of the platform-specific implementation.
59 #if defined(ASIO_WINDOWS_RUNTIME)
60  typedef detail::null_socket_service<Protocol> service_impl_type;
61 #elif defined(ASIO_HAS_IOCP)
62  typedef detail::win_iocp_socket_service<Protocol> service_impl_type;
63 #else
64  typedef detail::reactive_socket_service<Protocol> service_impl_type;
65 #endif
66 
67 public:
69 #if defined(GENERATING_DOCUMENTATION)
70  typedef implementation_defined implementation_type;
71 #else
73 #endif
74 
76 #if defined(GENERATING_DOCUMENTATION)
77  typedef implementation_defined native_type;
78 #else
80 #endif
81 
83 #if defined(GENERATING_DOCUMENTATION)
84  typedef implementation_defined native_handle_type;
85 #else
87 #endif
88 
91  : asio::detail::service_base<
92  socket_acceptor_service<Protocol> >(io_service),
93  service_impl_(io_service)
94  {
95  }
96 
98  void construct(implementation_type& impl)
99  {
100  service_impl_.construct(impl);
101  }
102 
103 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
104  void move_construct(implementation_type& impl,
106  implementation_type& other_impl)
107  {
108  service_impl_.move_construct(impl, other_impl);
109  }
110 
112  void move_assign(implementation_type& impl,
113  socket_acceptor_service& other_service,
114  implementation_type& other_impl)
115  {
116  service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
117  }
118 
121  template <typename Protocol1>
122  void converting_move_construct(implementation_type& impl,
123  typename socket_acceptor_service<
124  Protocol1>::implementation_type& other_impl,
125  typename enable_if<is_convertible<
126  Protocol1, Protocol>::value>::type* = 0)
127  {
128  service_impl_.template converting_move_construct<Protocol1>(
129  impl, other_impl);
130  }
131 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
132 
134  void destroy(implementation_type& impl)
135  {
136  service_impl_.destroy(impl);
137  }
138 
140  asio::error_code open(implementation_type& impl,
141  const protocol_type& protocol, asio::error_code& ec)
142  {
143  return service_impl_.open(impl, protocol, ec);
144  }
145 
147  asio::error_code assign(implementation_type& impl,
148  const protocol_type& protocol, const native_handle_type& native_acceptor,
149  asio::error_code& ec)
150  {
151  return service_impl_.assign(impl, protocol, native_acceptor, ec);
152  }
153 
155  bool is_open(const implementation_type& impl) const
156  {
157  return service_impl_.is_open(impl);
158  }
159 
161  asio::error_code cancel(implementation_type& impl,
162  asio::error_code& ec)
163  {
164  return service_impl_.cancel(impl, ec);
165  }
166 
168  asio::error_code bind(implementation_type& impl,
169  const endpoint_type& endpoint, asio::error_code& ec)
170  {
171  return service_impl_.bind(impl, endpoint, ec);
172  }
173 
176  asio::error_code listen(implementation_type& impl, int backlog,
177  asio::error_code& ec)
178  {
179  return service_impl_.listen(impl, backlog, ec);
180  }
181 
183  asio::error_code close(implementation_type& impl,
184  asio::error_code& ec)
185  {
186  return service_impl_.close(impl, ec);
187  }
188 
190  native_type native(implementation_type& impl)
191  {
192  return service_impl_.native_handle(impl);
193  }
194 
196  native_handle_type native_handle(implementation_type& impl)
197  {
198  return service_impl_.native_handle(impl);
199  }
200 
202  template <typename SettableSocketOption>
203  asio::error_code set_option(implementation_type& impl,
204  const SettableSocketOption& option, asio::error_code& ec)
205  {
206  return service_impl_.set_option(impl, option, ec);
207  }
208 
210  template <typename GettableSocketOption>
211  asio::error_code get_option(const implementation_type& impl,
212  GettableSocketOption& option, asio::error_code& ec) const
213  {
214  return service_impl_.get_option(impl, option, ec);
215  }
216 
218  template <typename IoControlCommand>
219  asio::error_code io_control(implementation_type& impl,
220  IoControlCommand& command, asio::error_code& ec)
221  {
222  return service_impl_.io_control(impl, command, ec);
223  }
224 
226  bool non_blocking(const implementation_type& impl) const
227  {
228  return service_impl_.non_blocking(impl);
229  }
230 
232  asio::error_code non_blocking(implementation_type& impl,
233  bool mode, asio::error_code& ec)
234  {
235  return service_impl_.non_blocking(impl, mode, ec);
236  }
237 
239  bool native_non_blocking(const implementation_type& impl) const
240  {
241  return service_impl_.native_non_blocking(impl);
242  }
243 
245  asio::error_code native_non_blocking(implementation_type& impl,
246  bool mode, asio::error_code& ec)
247  {
248  return service_impl_.native_non_blocking(impl, mode, ec);
249  }
250 
252  endpoint_type local_endpoint(const implementation_type& impl,
253  asio::error_code& ec) const
254  {
255  return service_impl_.local_endpoint(impl, ec);
256  }
257 
259  template <typename Protocol1, typename SocketService>
260  asio::error_code accept(implementation_type& impl,
262  endpoint_type* peer_endpoint, asio::error_code& ec,
263  typename enable_if<is_convertible<Protocol, Protocol1>::value>::type* = 0)
264  {
265  return service_impl_.accept(impl, peer, peer_endpoint, ec);
266  }
267 
269  template <typename Protocol1, typename SocketService, typename AcceptHandler>
270  ASIO_INITFN_RESULT_TYPE(AcceptHandler,
271  void (asio::error_code))
272  async_accept(implementation_type& impl,
274  endpoint_type* peer_endpoint,
275  ASIO_MOVE_ARG(AcceptHandler) handler,
276  typename enable_if<is_convertible<Protocol, Protocol1>::value>::type* = 0)
277  {
279  AcceptHandler, void (asio::error_code)> init(
280  ASIO_MOVE_CAST(AcceptHandler)(handler));
281 
282  service_impl_.async_accept(impl, peer, peer_endpoint, init.handler);
283 
284  return init.result.get();
285  }
286 
287 private:
288  // Destroy all user-defined handler objects owned by the service.
289  void shutdown_service()
290  {
291  service_impl_.shutdown_service();
292  }
293 
294  // The platform-specific implementation.
295  service_impl_type service_impl_;
296 };
297 
298 } // namespace asio
299 
301 
302 #endif // ASIO_SOCKET_ACCEPTOR_SERVICE_HPP
asio::error_code io_control(implementation_type &impl, IoControlCommand &command, asio::error_code &ec)
Perform an IO control command on the socket.
bool is_open(const implementation_type &impl) const
Determine whether the acceptor is open.
void construct(implementation_type &impl)
Construct a new socket acceptor implementation.
asio::error_code native_non_blocking(implementation_type &impl, bool mode, asio::error_code &ec)
Sets the non-blocking mode of the native acceptor implementation.
Class used to uniquely identify a service.
Definition: io_service.hpp:665
Provides core I/O functionality.
Definition: io_service.hpp:184
endpoint_type local_endpoint(const implementation_type &impl, asio::error_code &ec) const
Get the local endpoint.
bool native_non_blocking(const implementation_type &impl) const
Gets the non-blocking mode of the native acceptor implementation.
asio::error_code cancel(implementation_type &impl, asio::error_code &ec)
Cancel all asynchronous operations associated with the acceptor.
service_impl_type::native_handle_type native_type
(Deprecated: Use native_handle_type.) The native acceptor type.
basic_socket< Protocol1, SocketService > endpoint_type * peer_endpoint
asio::error_code non_blocking(implementation_type &impl, bool mode, asio::error_code &ec)
Sets the non-blocking mode of the acceptor.
asio::basic_streambuf< Allocator > MatchCondition enable_if< is_match_condition< MatchCondition >::value >::type *detail::async_result_init< ReadHandler, void(asio::error_code, std::size_t)> init(ASIO_MOVE_CAST(ReadHandler)(handler))
asio::error_code assign(implementation_type &impl, const protocol_type &protocol, const native_handle_type &native_acceptor, asio::error_code &ec)
Assign an existing native acceptor to a socket acceptor.
asio::error_code bind(implementation_type &impl, const endpoint_type &endpoint, asio::error_code &ec)
Bind the socket acceptor to the specified local endpoint.
asio::error_code close(implementation_type &impl, asio::error_code &ec)
Close a socket acceptor implementation.
Default service implementation for a socket acceptor.
ASIO_INITFN_RESULT_TYPE(AcceptHandler, void(asio::error_code)) async_accept(implementation_type &impl
Start an asynchronous accept.
void destroy(implementation_type &impl)
Destroy a socket acceptor implementation.
asio::error_code set_option(implementation_type &impl, const SettableSocketOption &option, asio::error_code &ec)
Set a socket option.
basic_socket< Protocol1, SocketService > endpoint_type ASIO_MOVE_ARG(AcceptHandler) handler
basic_socket< Protocol1, SocketService > & peer
asio::error_code listen(implementation_type &impl, int backlog, asio::error_code &ec)
asio::error_code get_option(const implementation_type &impl, GettableSocketOption &option, asio::error_code &ec) const
Get a socket option.
Protocol protocol_type
The protocol type.
socket_acceptor_service(asio::io_service &io_service)
Construct a new socket acceptor service for the specified io_service.
Class to represent an error code value.
Definition: error_code.hpp:80
asio::error_code open(implementation_type &impl, const protocol_type &protocol, asio::error_code &ec)
Open a new socket acceptor implementation.
native_type native(implementation_type &impl)
(Deprecated: Use native_handle().) Get the native acceptor implementation.
protocol_type::endpoint endpoint_type
The endpoint type.
static asio::detail::service_id< socket_acceptor_service< Protocol > > id
Definition: io_service.hpp:748
handler_type< Handler, Signature >::type handler
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
service_impl_type::native_handle_type native_handle_type
The native acceptor type.
async_result< typename handler_type< Handler, Signature >::type > result
native_handle_type native_handle(implementation_type &impl)
Get the native acceptor implementation.
Base class for all io_service services.
Definition: io_service.hpp:674
asio::error_code accept(implementation_type &impl, basic_socket< Protocol1, SocketService > &peer, endpoint_type *peer_endpoint, asio::error_code &ec, typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type *=0)
Accept a new connection.
bool non_blocking(const implementation_type &impl) const
Gets the non-blocking mode of the acceptor.
service_impl_type::implementation_type implementation_type
The native type of the socket acceptor.