Realistic 3D camera system
3D camera system components
stream_socket_service.hpp
Go to the documentation of this file.
1 //
2 // stream_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_STREAM_SOCKET_SERVICE_HPP
12 #define ASIO_STREAM_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
43  : public asio::detail::service_base<stream_socket_service<Protocol> >
44 #endif
45 {
46 public:
47 #if defined(GENERATING_DOCUMENTATION)
48  static asio::io_service::id id;
50 #endif
51 
53  typedef Protocol protocol_type;
54 
56  typedef typename Protocol::endpoint endpoint_type;
57 
58 private:
59  // The type of the platform-specific implementation.
60 #if defined(ASIO_WINDOWS_RUNTIME)
61  typedef detail::winrt_ssocket_service<Protocol> service_impl_type;
62 #elif defined(ASIO_HAS_IOCP)
63  typedef detail::win_iocp_socket_service<Protocol> service_impl_type;
64 #else
65  typedef detail::reactive_socket_service<Protocol> service_impl_type;
66 #endif
67 
68 public:
70 #if defined(GENERATING_DOCUMENTATION)
71  typedef implementation_defined implementation_type;
72 #else
74 #endif
75 
77 #if defined(GENERATING_DOCUMENTATION)
78  typedef implementation_defined native_type;
79 #else
81 #endif
82 
84 #if defined(GENERATING_DOCUMENTATION)
85  typedef implementation_defined native_handle_type;
86 #else
88 #endif
89 
92  : asio::detail::service_base<
93  stream_socket_service<Protocol> >(io_service),
94  service_impl_(io_service)
95  {
96  }
97 
99  void construct(implementation_type& impl)
100  {
101  service_impl_.construct(impl);
102  }
103 
104 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
105  void move_construct(implementation_type& impl,
107  implementation_type& other_impl)
108  {
109  service_impl_.move_construct(impl, other_impl);
110  }
111 
113  void move_assign(implementation_type& impl,
114  stream_socket_service& other_service,
115  implementation_type& other_impl)
116  {
117  service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
118  }
119 
122  template <typename Protocol1>
123  void converting_move_construct(implementation_type& impl,
124  typename stream_socket_service<
125  Protocol1>::implementation_type& other_impl,
126  typename enable_if<is_convertible<
127  Protocol1, Protocol>::value>::type* = 0)
128  {
129  service_impl_.template converting_move_construct<Protocol1>(
130  impl, other_impl);
131  }
132 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
133 
135  void destroy(implementation_type& impl)
136  {
137  service_impl_.destroy(impl);
138  }
139 
141  asio::error_code open(implementation_type& impl,
142  const protocol_type& protocol, asio::error_code& ec)
143  {
144  if (protocol.type() == ASIO_OS_DEF(SOCK_STREAM))
145  service_impl_.open(impl, protocol, ec);
146  else
148  return ec;
149  }
150 
152  asio::error_code assign(implementation_type& impl,
153  const protocol_type& protocol, const native_handle_type& native_socket,
154  asio::error_code& ec)
155  {
156  return service_impl_.assign(impl, protocol, native_socket, ec);
157  }
158 
160  bool is_open(const implementation_type& impl) const
161  {
162  return service_impl_.is_open(impl);
163  }
164 
166  asio::error_code close(implementation_type& impl,
167  asio::error_code& ec)
168  {
169  return service_impl_.close(impl, ec);
170  }
171 
173  native_type native(implementation_type& impl)
174  {
175  return service_impl_.native_handle(impl);
176  }
177 
179  native_handle_type native_handle(implementation_type& impl)
180  {
181  return service_impl_.native_handle(impl);
182  }
183 
185  asio::error_code cancel(implementation_type& impl,
186  asio::error_code& ec)
187  {
188  return service_impl_.cancel(impl, ec);
189  }
190 
192  bool at_mark(const implementation_type& impl,
193  asio::error_code& ec) const
194  {
195  return service_impl_.at_mark(impl, ec);
196  }
197 
199  std::size_t available(const implementation_type& impl,
200  asio::error_code& ec) const
201  {
202  return service_impl_.available(impl, ec);
203  }
204 
206  asio::error_code bind(implementation_type& impl,
207  const endpoint_type& endpoint, asio::error_code& ec)
208  {
209  return service_impl_.bind(impl, endpoint, ec);
210  }
211 
213  asio::error_code connect(implementation_type& impl,
214  const endpoint_type& peer_endpoint, asio::error_code& ec)
215  {
216  return service_impl_.connect(impl, peer_endpoint, ec);
217  }
218 
220  template <typename ConnectHandler>
221  ASIO_INITFN_RESULT_TYPE(ConnectHandler,
222  void (asio::error_code))
223  async_connect(implementation_type& impl,
224  const endpoint_type& peer_endpoint,
225  ASIO_MOVE_ARG(ConnectHandler) handler)
226  {
228  ConnectHandler, void (asio::error_code)> init(
229  ASIO_MOVE_CAST(ConnectHandler)(handler));
230 
231  service_impl_.async_connect(impl, peer_endpoint, init.handler);
232 
233  return init.result.get();
234  }
235 
237  template <typename SettableSocketOption>
238  asio::error_code set_option(implementation_type& impl,
239  const SettableSocketOption& option, asio::error_code& ec)
240  {
241  return service_impl_.set_option(impl, option, ec);
242  }
243 
245  template <typename GettableSocketOption>
246  asio::error_code get_option(const implementation_type& impl,
247  GettableSocketOption& option, asio::error_code& ec) const
248  {
249  return service_impl_.get_option(impl, option, ec);
250  }
251 
253  template <typename IoControlCommand>
254  asio::error_code io_control(implementation_type& impl,
255  IoControlCommand& command, asio::error_code& ec)
256  {
257  return service_impl_.io_control(impl, command, ec);
258  }
259 
261  bool non_blocking(const implementation_type& impl) const
262  {
263  return service_impl_.non_blocking(impl);
264  }
265 
267  asio::error_code non_blocking(implementation_type& impl,
268  bool mode, asio::error_code& ec)
269  {
270  return service_impl_.non_blocking(impl, mode, ec);
271  }
272 
274  bool native_non_blocking(const implementation_type& impl) const
275  {
276  return service_impl_.native_non_blocking(impl);
277  }
278 
280  asio::error_code native_non_blocking(implementation_type& impl,
281  bool mode, asio::error_code& ec)
282  {
283  return service_impl_.native_non_blocking(impl, mode, ec);
284  }
285 
287  endpoint_type local_endpoint(const implementation_type& impl,
288  asio::error_code& ec) const
289  {
290  return service_impl_.local_endpoint(impl, ec);
291  }
292 
294  endpoint_type remote_endpoint(const implementation_type& impl,
295  asio::error_code& ec) const
296  {
297  return service_impl_.remote_endpoint(impl, ec);
298  }
299 
301  asio::error_code shutdown(implementation_type& impl,
303  {
304  return service_impl_.shutdown(impl, what, ec);
305  }
306 
308  template <typename ConstBufferSequence>
309  std::size_t send(implementation_type& impl,
310  const ConstBufferSequence& buffers,
312  {
313  return service_impl_.send(impl, buffers, flags, ec);
314  }
315 
317  template <typename ConstBufferSequence, typename WriteHandler>
318  ASIO_INITFN_RESULT_TYPE(WriteHandler,
319  void (asio::error_code, std::size_t))
320  async_send(implementation_type& impl,
321  const ConstBufferSequence& buffers,
323  ASIO_MOVE_ARG(WriteHandler) handler)
324  {
326  WriteHandler, void (asio::error_code, std::size_t)> init(
327  ASIO_MOVE_CAST(WriteHandler)(handler));
328 
329  service_impl_.async_send(impl, buffers, flags, init.handler);
330 
331  return init.result.get();
332  }
333 
335  template <typename MutableBufferSequence>
336  std::size_t receive(implementation_type& impl,
337  const MutableBufferSequence& buffers,
339  {
340  return service_impl_.receive(impl, buffers, flags, ec);
341  }
342 
344  template <typename MutableBufferSequence, typename ReadHandler>
345  ASIO_INITFN_RESULT_TYPE(ReadHandler,
346  void (asio::error_code, std::size_t))
347  async_receive(implementation_type& impl,
348  const MutableBufferSequence& buffers,
350  ASIO_MOVE_ARG(ReadHandler) handler)
351  {
353  ReadHandler, void (asio::error_code, std::size_t)> init(
354  ASIO_MOVE_CAST(ReadHandler)(handler));
355 
356  service_impl_.async_receive(impl, buffers, flags, init.handler);
357 
358  return init.result.get();
359  }
360 
361 private:
362  // Destroy all user-defined handler objects owned by the service.
363  void shutdown_service()
364  {
365  service_impl_.shutdown_service();
366  }
367 
368  // The platform-specific implementation.
369  service_impl_type service_impl_;
370 };
371 
372 } // namespace asio
373 
375 
376 #endif // ASIO_STREAM_SOCKET_SERVICE_HPP
const MutableBufferSequence socket_base::message_flags ASIO_MOVE_ARG(ReadHandler) handler)
int message_flags
Bitmask type for flags that can be passed to send and receive operations.
Definition: socket_base.hpp:53
const ConstBufferSequence socket_base::message_flags flags
asio::error_code assign(implementation_type &impl, const protocol_type &protocol, const native_handle_type &native_socket, asio::error_code &ec)
asio::error_code bind(implementation_type &impl, const endpoint_type &endpoint, asio::error_code &ec)
std::size_t receive(implementation_type &impl, const MutableBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec)
Receive some data from the peer.
bool at_mark(const base_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.
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
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 native_non_blocking(implementation_type &impl, bool mode, asio::error_code &ec)
Sets the non-blocking mode of the native socket implementation.
bool is_open(const implementation_type &impl) const
Determine whether the socket is open.
#define ASIO_OS_DEF(c)
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 stream socket.
Protocol::endpoint endpoint_type
The endpoint type.
Default service implementation for a stream socket.
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 stream socket implementation.
asio::error_code shutdown(implementation_type &impl, socket_base::shutdown_type what, asio::error_code &ec)
Disable sends or receives on the socket.
native_handle_type native_handle(implementation_type &impl)
Get the native socket implementation.
bool non_blocking(const implementation_type &impl) const
Gets the non-blocking mode of the socket.
endpoint_type local_endpoint(const implementation_type &impl, asio::error_code &ec) const
Get the local endpoint.
size_t receive(base_implementation_type &impl, const MutableBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec)
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)
service_impl_type::native_handle_type native_type
(Deprecated: Use native_handle_type.) The native socket type.
Invalid argument.
Definition: error.hpp:113
endpoint_type remote_endpoint(const implementation_type &impl, asio::error_code &ec) const
Get the remote endpoint.
native_type native(implementation_type &impl)
(Deprecated: Use native_handle().) Get the native socket implementation.
asio::error_code io_control(base_implementation_type &impl, IO_Control_Command &command, asio::error_code &ec)
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 close(implementation_type &impl, asio::error_code &ec)
Close a stream socket implementation.
asio::error_code connect(implementation_type &impl, const endpoint_type &peer_endpoint, asio::error_code &ec)
Connect the stream socket to the specified endpoint.
const endpoint_type ASIO_MOVE_ARG(ConnectHandler) handler)
asio::error_code set_option(implementation_type &impl, const Option &option, asio::error_code &ec)
asio::error_code cancel(implementation_type &impl, asio::error_code &ec)
Cancel all asynchronous operations associated with the socket.
asio::error_code set_option(implementation_type &impl, const SettableSocketOption &option, asio::error_code &ec)
Set a socket option.
shutdown_type
Different ways a socket may be shutdown.
Definition: socket_base.hpp:34
service_impl_type::implementation_type implementation_type
The type of a stream socket implementation.
asio::error_code open(implementation_type &impl, const protocol_type &protocol, asio::error_code &ec)
Open a stream socket.
asio::error_code open(implementation_type &impl, const protocol_type &protocol, asio::error_code &ec)
void move_construct(implementation_type &impl, implementation_type &other_impl)
bool native_non_blocking(const implementation_type &impl) const
Gets the non-blocking mode of the native socket implementation.
bool is_open(const base_implementation_type &impl) const
ASIO_INITFN_RESULT_TYPE(ConnectHandler, void(asio::error_code)) async_connect(implementation_type &impl
Start an asynchronous connect.
Class to represent an error code value.
Definition: error_code.hpp:80
service_impl_type::native_handle_type 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
void construct(implementation_type &impl)
Construct a new stream socket implementation.
static asio::detail::service_id< stream_socket_service< Protocol > > id
Definition: io_service.hpp:748
void async_receive(base_implementation_type &impl, const MutableBufferSequence &buffers, socket_base::message_flags flags, Handler &handler)
stream_socket_service(asio::io_service &io_service)
Construct a new stream socket service for the specified io_service.
asio::error_code bind(implementation_type &impl, const endpoint_type &endpoint, asio::error_code &ec)
Bind the stream socket to the specified local endpoint.
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
async_result< typename handler_type< Handler, Signature >::type > result
native_handle_type native_handle(implementation_type &impl)
asio::error_code non_blocking(implementation_type &impl, bool mode, asio::error_code &ec)
Sets the non-blocking mode of the socket.
Protocol protocol_type
The protocol type.
std::size_t available(const implementation_type &impl, asio::error_code &ec) const
Determine the number of bytes available for reading.
Base class for all io_service services.
Definition: io_service.hpp:674
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.
asio::error_code get_option(const implementation_type &impl, GettableSocketOption &option, asio::error_code &ec) const
Get a socket option.
const ConstBufferSequence & buffers
const ConstBufferSequence socket_base::message_flags ASIO_MOVE_ARG(WriteHandler) 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