Realistic 3D camera system
3D camera system components
seq_packet_socket_service.hpp
Go to the documentation of this file.
1 //
2 // seq_packet_socket_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_SEQ_PACKET_SOCKET_SERVICE_HPP
12 #define ASIO_SEQ_PACKET_SOCKET_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 <cstddef>
20 #include "asio/async_result.hpp"
22 #include "asio/error.hpp"
23 #include "asio/io_service.hpp"
24 
25 #if defined(ASIO_WINDOWS_RUNTIME)
27 #elif defined(ASIO_HAS_IOCP)
29 #else
31 #endif
32 
34 
35 namespace asio {
36 
38 template <typename Protocol>
40 #if defined(GENERATING_DOCUMENTATION)
42 #else
44  seq_packet_socket_service<Protocol> >
45 #endif
46 {
47 public:
48 #if defined(GENERATING_DOCUMENTATION)
49  static asio::io_service::id id;
51 #endif
52 
54  typedef Protocol protocol_type;
55 
57  typedef typename Protocol::endpoint endpoint_type;
58 
59 private:
60  // The type of the platform-specific implementation.
61 #if defined(ASIO_WINDOWS_RUNTIME)
62  typedef detail::null_socket_service<Protocol> service_impl_type;
63 #elif defined(ASIO_HAS_IOCP)
64  typedef detail::win_iocp_socket_service<Protocol> service_impl_type;
65 #else
66  typedef detail::reactive_socket_service<Protocol> service_impl_type;
67 #endif
68 
69 public:
71 #if defined(GENERATING_DOCUMENTATION)
72  typedef implementation_defined implementation_type;
73 #else
75 #endif
76 
78 #if defined(GENERATING_DOCUMENTATION)
79  typedef implementation_defined native_type;
80 #else
82 #endif
83 
85 #if defined(GENERATING_DOCUMENTATION)
86  typedef implementation_defined native_handle_type;
87 #else
89 #endif
90 
94  : asio::detail::service_base<
95  seq_packet_socket_service<Protocol> >(io_service),
96  service_impl_(io_service)
97  {
98  }
99 
101  void construct(implementation_type& impl)
102  {
103  service_impl_.construct(impl);
104  }
105 
106 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
107  void move_construct(implementation_type& impl,
109  implementation_type& other_impl)
110  {
111  service_impl_.move_construct(impl, other_impl);
112  }
113 
115  void move_assign(implementation_type& impl,
116  seq_packet_socket_service& other_service,
117  implementation_type& other_impl)
118  {
119  service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
120  }
121 
124  template <typename Protocol1>
125  void converting_move_construct(implementation_type& impl,
126  typename seq_packet_socket_service<
127  Protocol1>::implementation_type& other_impl,
128  typename enable_if<is_convertible<
129  Protocol1, Protocol>::value>::type* = 0)
130  {
131  service_impl_.template converting_move_construct<Protocol1>(
132  impl, other_impl);
133  }
134 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
135 
137  void destroy(implementation_type& impl)
138  {
139  service_impl_.destroy(impl);
140  }
141 
143  asio::error_code open(implementation_type& impl,
144  const protocol_type& protocol, asio::error_code& ec)
145  {
146  if (protocol.type() == ASIO_OS_DEF(SOCK_SEQPACKET))
147  service_impl_.open(impl, protocol, ec);
148  else
150  return ec;
151  }
152 
154  asio::error_code assign(implementation_type& impl,
155  const protocol_type& protocol, const native_handle_type& native_socket,
156  asio::error_code& ec)
157  {
158  return service_impl_.assign(impl, protocol, native_socket, ec);
159  }
160 
162  bool is_open(const implementation_type& impl) const
163  {
164  return service_impl_.is_open(impl);
165  }
166 
168  asio::error_code close(implementation_type& impl,
169  asio::error_code& ec)
170  {
171  return service_impl_.close(impl, ec);
172  }
173 
175  native_type native(implementation_type& impl)
176  {
177  return service_impl_.native_handle(impl);
178  }
179 
181  native_handle_type native_handle(implementation_type& impl)
182  {
183  return service_impl_.native_handle(impl);
184  }
185 
187  asio::error_code cancel(implementation_type& impl,
188  asio::error_code& ec)
189  {
190  return service_impl_.cancel(impl, ec);
191  }
192 
194  bool at_mark(const implementation_type& impl,
195  asio::error_code& ec) const
196  {
197  return service_impl_.at_mark(impl, ec);
198  }
199 
201  std::size_t available(const implementation_type& impl,
202  asio::error_code& ec) const
203  {
204  return service_impl_.available(impl, ec);
205  }
206 
208  asio::error_code bind(implementation_type& impl,
209  const endpoint_type& endpoint, asio::error_code& ec)
210  {
211  return service_impl_.bind(impl, endpoint, ec);
212  }
213 
215  asio::error_code connect(implementation_type& impl,
216  const endpoint_type& peer_endpoint, asio::error_code& ec)
217  {
218  return service_impl_.connect(impl, peer_endpoint, ec);
219  }
220 
222  template <typename ConnectHandler>
223  ASIO_INITFN_RESULT_TYPE(ConnectHandler,
224  void (asio::error_code))
225  async_connect(implementation_type& impl,
226  const endpoint_type& peer_endpoint,
227  ASIO_MOVE_ARG(ConnectHandler) handler)
228  {
230  ConnectHandler, void (asio::error_code)> init(
231  ASIO_MOVE_CAST(ConnectHandler)(handler));
232 
233  service_impl_.async_connect(impl, peer_endpoint, init.handler);
234 
235  return init.result.get();
236  }
237 
239  template <typename SettableSocketOption>
240  asio::error_code set_option(implementation_type& impl,
241  const SettableSocketOption& option, asio::error_code& ec)
242  {
243  return service_impl_.set_option(impl, option, ec);
244  }
245 
247  template <typename GettableSocketOption>
248  asio::error_code get_option(const implementation_type& impl,
249  GettableSocketOption& option, asio::error_code& ec) const
250  {
251  return service_impl_.get_option(impl, option, ec);
252  }
253 
255  template <typename IoControlCommand>
256  asio::error_code io_control(implementation_type& impl,
257  IoControlCommand& command, asio::error_code& ec)
258  {
259  return service_impl_.io_control(impl, command, ec);
260  }
261 
263  bool non_blocking(const implementation_type& impl) const
264  {
265  return service_impl_.non_blocking(impl);
266  }
267 
269  asio::error_code non_blocking(implementation_type& impl,
270  bool mode, asio::error_code& ec)
271  {
272  return service_impl_.non_blocking(impl, mode, ec);
273  }
274 
276  bool native_non_blocking(const implementation_type& impl) const
277  {
278  return service_impl_.native_non_blocking(impl);
279  }
280 
282  asio::error_code native_non_blocking(implementation_type& impl,
283  bool mode, asio::error_code& ec)
284  {
285  return service_impl_.native_non_blocking(impl, mode, ec);
286  }
287 
289  endpoint_type local_endpoint(const implementation_type& impl,
290  asio::error_code& ec) const
291  {
292  return service_impl_.local_endpoint(impl, ec);
293  }
294 
296  endpoint_type remote_endpoint(const implementation_type& impl,
297  asio::error_code& ec) const
298  {
299  return service_impl_.remote_endpoint(impl, ec);
300  }
301 
303  asio::error_code shutdown(implementation_type& impl,
305  {
306  return service_impl_.shutdown(impl, what, ec);
307  }
308 
310  template <typename ConstBufferSequence>
311  std::size_t send(implementation_type& impl,
312  const ConstBufferSequence& buffers,
314  {
315  return service_impl_.send(impl, buffers, flags, ec);
316  }
317 
319  template <typename ConstBufferSequence, typename WriteHandler>
320  ASIO_INITFN_RESULT_TYPE(WriteHandler,
321  void (asio::error_code, std::size_t))
322  async_send(implementation_type& impl,
323  const ConstBufferSequence& buffers,
325  ASIO_MOVE_ARG(WriteHandler) handler)
326  {
328  WriteHandler, void (asio::error_code, std::size_t)> init(
329  ASIO_MOVE_CAST(WriteHandler)(handler));
330 
331  service_impl_.async_send(impl, buffers, flags, init.handler);
332 
333  return init.result.get();
334  }
335 
337  template <typename MutableBufferSequence>
338  std::size_t receive(implementation_type& impl,
339  const MutableBufferSequence& buffers, socket_base::message_flags in_flags,
341  {
342  return service_impl_.receive_with_flags(impl,
343  buffers, in_flags, out_flags, ec);
344  }
345 
347  template <typename MutableBufferSequence, typename ReadHandler>
348  ASIO_INITFN_RESULT_TYPE(ReadHandler,
349  void (asio::error_code, std::size_t))
350  async_receive(implementation_type& impl,
351  const MutableBufferSequence& buffers, socket_base::message_flags in_flags,
353  ASIO_MOVE_ARG(ReadHandler) handler)
354  {
356  ReadHandler, void (asio::error_code, std::size_t)> init(
357  ASIO_MOVE_CAST(ReadHandler)(handler));
358 
359  service_impl_.async_receive_with_flags(impl,
360  buffers, in_flags, out_flags, init.handler);
361 
362  return init.result.get();
363  }
364 
365 private:
366  // Destroy all user-defined handler objects owned by the service.
367  void shutdown_service()
368  {
369  service_impl_.shutdown_service();
370  }
371 
372  // The platform-specific implementation.
373  service_impl_type service_impl_;
374 };
375 
376 } // namespace asio
377 
379 
380 #endif // ASIO_SEQ_PACKET_SOCKET_SERVICE_HPP
bool non_blocking(const implementation_type &impl) const
Gets the non-blocking mode of the socket.
int message_flags
Bitmask type for flags that can be passed to send and receive operations.
Definition: socket_base.hpp:53
asio::error_code assign(implementation_type &impl, const protocol_type &protocol, const native_handle_type &native_socket, asio::error_code &ec)
asio::error_code get_option(const implementation_type &impl, GettableSocketOption &option, asio::error_code &ec) const
Get a socket option.
asio::error_code bind(implementation_type &impl, const endpoint_type &endpoint, asio::error_code &ec)
bool at_mark(const base_implementation_type &impl, asio::error_code &ec) const
Class used to uniquely identify a service.
Definition: io_service.hpp:665
asio::error_code connect(implementation_type &impl, const endpoint_type &peer_endpoint, asio::error_code &ec)
Provides core I/O functionality.
Definition: io_service.hpp:184
void construct(implementation_type &impl)
Construct a new sequenced packet socket implementation.
service_impl_type::native_handle_type native_handle_type
The native socket type.
asio::error_code cancel(implementation_type &impl, asio::error_code &ec)
Cancel all asynchronous operations associated with the socket.
bool native_non_blocking(const implementation_type &impl) const
Gets the non-blocking mode of the native socket implementation.
asio::error_code open(implementation_type &impl, const protocol_type &protocol, asio::error_code &ec)
Open a sequenced packet socket.
#define ASIO_OS_DEF(c)
const MutableBufferSequence socket_base::message_flags in_flags
asio::error_code get_option(const implementation_type &impl, Option &option, asio::error_code &ec) const
ASIO_DECL void destroy(base_implementation_type &impl)
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))
void destroy(implementation_type &impl)
Destroy a sequenced packet socket implementation.
bool is_open(const implementation_type &impl) const
Determine whether the socket is open.
const endpoint_type ASIO_MOVE_ARG(ConnectHandler) handler)
size_t send(base_implementation_type &impl, const ConstBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec)
void async_connect(implementation_type &impl, const endpoint_type &peer_endpoint, Handler &handler)
Invalid argument.
Definition: error.hpp:113
asio::error_code io_control(implementation_type &impl, IoControlCommand &command, asio::error_code &ec)
Perform an IO control command on the socket.
asio::error_code io_control(base_implementation_type &impl, IO_Control_Command &command, asio::error_code &ec)
asio::error_code non_blocking(implementation_type &impl, bool mode, asio::error_code &ec)
Sets the non-blocking mode of the socket.
void async_receive_with_flags(base_implementation_type &impl, const MutableBufferSequence &buffers, socket_base::message_flags in_flags, socket_base::message_flags &out_flags, Handler &handler)
void move_assign(implementation_type &impl, reactive_socket_service_base &other_service, implementation_type &other_impl)
endpoint_type local_endpoint(const implementation_type &impl, asio::error_code &ec) const
ASIO_DECL void construct(base_implementation_type &impl)
asio::error_code assign(implementation_type &impl, const protocol_type &protocol, const native_handle_type &native_socket, asio::error_code &ec)
Assign an existing native socket to a sequenced packet socket.
const MutableBufferSequence socket_base::message_flags socket_base::message_flags & out_flags
size_t receive_with_flags(base_implementation_type &impl, const MutableBufferSequence &buffers, socket_base::message_flags in_flags, socket_base::message_flags &out_flags, asio::error_code &ec)
asio::error_code set_option(implementation_type &impl, const Option &option, asio::error_code &ec)
endpoint_type remote_endpoint(const implementation_type &impl, asio::error_code &ec) const
Get the remote endpoint.
Protocol::endpoint endpoint_type
The endpoint type.
asio::error_code set_option(implementation_type &impl, const SettableSocketOption &option, asio::error_code &ec)
Set a socket option.
std::size_t send(implementation_type &impl, const ConstBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec)
Send the given data to the peer.
Default service implementation for a sequenced packet socket.
const ConstBufferSequence socket_base::message_flags ASIO_MOVE_ARG(WriteHandler) handler)
ASIO_INITFN_RESULT_TYPE(ConnectHandler, void(asio::error_code)) async_connect(implementation_type &impl
Start an asynchronous connect.
Protocol protocol_type
The protocol type.
shutdown_type
Different ways a socket may be shutdown.
Definition: socket_base.hpp:34
asio::error_code bind(implementation_type &impl, const endpoint_type &endpoint, asio::error_code &ec)
Bind the sequenced packet socket to the specified local endpoint.
asio::error_code open(implementation_type &impl, const protocol_type &protocol, asio::error_code &ec)
service_impl_type::implementation_type implementation_type
The type of a sequenced packet socket implementation.
void move_construct(implementation_type &impl, implementation_type &other_impl)
bool is_open(const base_implementation_type &impl) const
asio::error_code connect(implementation_type &impl, const endpoint_type &peer_endpoint, asio::error_code &ec)
Connect the sequenced packet socket to the specified endpoint.
Class to represent an error code value.
Definition: error_code.hpp:80
service_impl_type::native_handle_type native_type
(Deprecated: Use native_handle_type.) The native socket type.
void async_send(base_implementation_type &impl, const ConstBufferSequence &buffers, socket_base::message_flags flags, Handler &handler)
ASIO_DECL asio::error_code close(base_implementation_type &impl, asio::error_code &ec)
bool native_non_blocking(const base_implementation_type &impl) const
native_type native(implementation_type &impl)
(Deprecated: Use native_handle().) Get the native socket implementation.
static asio::detail::service_id< seq_packet_socket_service< Protocol > > id
Definition: io_service.hpp:748
endpoint_type local_endpoint(const implementation_type &impl, asio::error_code &ec) const
Get the local endpoint.
asio::error_code native_non_blocking(implementation_type &impl, bool mode, asio::error_code &ec)
Sets the non-blocking mode of the native socket implementation.
ASIO_DECL asio::error_code cancel(base_implementation_type &impl, asio::error_code &ec)
handler_type< Handler, Signature >::type handler
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
bool non_blocking(const base_implementation_type &impl) const
std::size_t receive(implementation_type &impl, const MutableBufferSequence &buffers, socket_base::message_flags in_flags, socket_base::message_flags &out_flags, asio::error_code &ec)
Receive some data from the peer.
async_result< typename handler_type< Handler, Signature >::type > result
native_handle_type native_handle(implementation_type &impl)
Base class for all io_service services.
Definition: io_service.hpp:674
asio::error_code close(implementation_type &impl, asio::error_code &ec)
Close a sequenced packet socket implementation.
const ConstBufferSequence socket_base::message_flags flags
std::size_t available(const implementation_type &impl, asio::error_code &ec) const
Determine the number of bytes available for reading.
seq_packet_socket_service(asio::io_service &io_service)
native_handle_type native_handle(implementation_type &impl)
Get the native socket implementation.
const MutableBufferSequence socket_base::message_flags socket_base::message_flags ASIO_MOVE_ARG(ReadHandler) handler)
std::size_t available(const base_implementation_type &impl, asio::error_code &ec) const
asio::error_code shutdown(base_implementation_type &impl, socket_base::shutdown_type what, asio::error_code &ec)
endpoint_type remote_endpoint(const implementation_type &impl, asio::error_code &ec) const
bool at_mark(const implementation_type &impl, asio::error_code &ec) const
Determine whether the socket is at the out-of-band data mark.
asio::error_code shutdown(implementation_type &impl, socket_base::shutdown_type what, asio::error_code &ec)
Disable sends or receives on the socket.