Realistic 3D camera system
3D camera system components
basic_stream_socket.hpp
Go to the documentation of this file.
1 //
2 // basic_stream_socket.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_BASIC_STREAM_SOCKET_HPP
12 #define ASIO_BASIC_STREAM_SOCKET_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"
21 #include "asio/basic_socket.hpp"
24 #include "asio/error.hpp"
26 
28 
29 namespace asio {
30 
32 
43 template <typename Protocol,
44  typename StreamSocketService = stream_socket_service<Protocol> >
46  : public basic_socket<Protocol, StreamSocketService>
47 {
48 public:
51  typedef typename StreamSocketService::native_handle_type native_type;
52 
54  typedef typename StreamSocketService::native_handle_type native_handle_type;
55 
57  typedef Protocol protocol_type;
58 
60  typedef typename Protocol::endpoint endpoint_type;
61 
63 
72  : basic_socket<Protocol, StreamSocketService>(io_service)
73  {
74  }
75 
77 
89  const protocol_type& protocol)
90  : basic_socket<Protocol, StreamSocketService>(io_service, protocol)
91  {
92  }
93 
96 
110  const endpoint_type& endpoint)
111  : basic_socket<Protocol, StreamSocketService>(io_service, endpoint)
112  {
113  }
114 
116 
130  const protocol_type& protocol, const native_handle_type& native_socket)
131  : basic_socket<Protocol, StreamSocketService>(
132  io_service, protocol, native_socket)
133  {
134  }
135 
136 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
137 
150  {
151  }
152 
154 
163  basic_stream_socket& operator=(basic_stream_socket&& other)
164  {
167  return *this;
168  }
169 
172 
181  template <typename Protocol1, typename StreamSocketService1>
184  typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
187  Protocol1, StreamSocketService1>)(other))
188  {
189  }
190 
192 
201  template <typename Protocol1, typename StreamSocketService1>
203  basic_stream_socket>::type& operator=(
205  {
208  Protocol1, StreamSocketService1>)(other));
209  return *this;
210  }
211 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
212 
214 
238  template <typename ConstBufferSequence>
239  std::size_t send(const ConstBufferSequence& buffers)
240  {
241  asio::error_code ec;
242  std::size_t s = this->get_service().send(
243  this->get_implementation(), buffers, 0, ec);
244  asio::detail::throw_error(ec, "send");
245  return s;
246  }
247 
249 
275  template <typename ConstBufferSequence>
276  std::size_t send(const ConstBufferSequence& buffers,
278  {
279  asio::error_code ec;
280  std::size_t s = this->get_service().send(
281  this->get_implementation(), buffers, flags, ec);
282  asio::detail::throw_error(ec, "send");
283  return s;
284  }
285 
287 
304  template <typename ConstBufferSequence>
305  std::size_t send(const ConstBufferSequence& buffers,
307  {
308  return this->get_service().send(
309  this->get_implementation(), buffers, flags, ec);
310  }
311 
313 
347  template <typename ConstBufferSequence, typename WriteHandler>
348  ASIO_INITFN_RESULT_TYPE(WriteHandler,
349  void (asio::error_code, std::size_t))
350  async_send(const ConstBufferSequence& buffers,
351  ASIO_MOVE_ARG(WriteHandler) handler)
352  {
353  // If you get an error on the following line it means that your handler does
354  // not meet the documented type requirements for a WriteHandler.
355  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
356 
357  return this->get_service().async_send(
358  this->get_implementation(), buffers, 0,
359  ASIO_MOVE_CAST(WriteHandler)(handler));
360  }
361 
363 
399  template <typename ConstBufferSequence, typename WriteHandler>
400  ASIO_INITFN_RESULT_TYPE(WriteHandler,
401  void (asio::error_code, std::size_t))
402  async_send(const ConstBufferSequence& buffers,
404  ASIO_MOVE_ARG(WriteHandler) handler)
405  {
406  // If you get an error on the following line it means that your handler does
407  // not meet the documented type requirements for a WriteHandler.
408  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
409 
410  return this->get_service().async_send(
411  this->get_implementation(), buffers, flags,
412  ASIO_MOVE_CAST(WriteHandler)(handler));
413  }
414 
416 
443  template <typename MutableBufferSequence>
444  std::size_t receive(const MutableBufferSequence& buffers)
445  {
446  asio::error_code ec;
447  std::size_t s = this->get_service().receive(
448  this->get_implementation(), buffers, 0, ec);
449  asio::detail::throw_error(ec, "receive");
450  return s;
451  }
452 
454 
483  template <typename MutableBufferSequence>
484  std::size_t receive(const MutableBufferSequence& buffers,
486  {
487  asio::error_code ec;
488  std::size_t s = this->get_service().receive(
489  this->get_implementation(), buffers, flags, ec);
490  asio::detail::throw_error(ec, "receive");
491  return s;
492  }
493 
495 
512  template <typename MutableBufferSequence>
513  std::size_t receive(const MutableBufferSequence& buffers,
515  {
516  return this->get_service().receive(
517  this->get_implementation(), buffers, flags, ec);
518  }
519 
521 
557  template <typename MutableBufferSequence, typename ReadHandler>
558  ASIO_INITFN_RESULT_TYPE(ReadHandler,
559  void (asio::error_code, std::size_t))
560  async_receive(const MutableBufferSequence& buffers,
561  ASIO_MOVE_ARG(ReadHandler) handler)
562  {
563  // If you get an error on the following line it means that your handler does
564  // not meet the documented type requirements for a ReadHandler.
565  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
566 
567  return this->get_service().async_receive(this->get_implementation(),
568  buffers, 0, ASIO_MOVE_CAST(ReadHandler)(handler));
569  }
570 
572 
610  template <typename MutableBufferSequence, typename ReadHandler>
611  ASIO_INITFN_RESULT_TYPE(ReadHandler,
612  void (asio::error_code, std::size_t))
613  async_receive(const MutableBufferSequence& buffers,
615  ASIO_MOVE_ARG(ReadHandler) handler)
616  {
617  // If you get an error on the following line it means that your handler does
618  // not meet the documented type requirements for a ReadHandler.
619  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
620 
621  return this->get_service().async_receive(this->get_implementation(),
622  buffers, flags, ASIO_MOVE_CAST(ReadHandler)(handler));
623  }
624 
626 
652  template <typename ConstBufferSequence>
653  std::size_t write_some(const ConstBufferSequence& buffers)
654  {
655  asio::error_code ec;
656  std::size_t s = this->get_service().send(
657  this->get_implementation(), buffers, 0, ec);
658  asio::detail::throw_error(ec, "write_some");
659  return s;
660  }
661 
663 
678  template <typename ConstBufferSequence>
679  std::size_t write_some(const ConstBufferSequence& buffers,
680  asio::error_code& ec)
681  {
682  return this->get_service().send(this->get_implementation(), buffers, 0, ec);
683  }
684 
686 
720  template <typename ConstBufferSequence, typename WriteHandler>
721  ASIO_INITFN_RESULT_TYPE(WriteHandler,
722  void (asio::error_code, std::size_t))
723  async_write_some(const ConstBufferSequence& buffers,
724  ASIO_MOVE_ARG(WriteHandler) handler)
725  {
726  // If you get an error on the following line it means that your handler does
727  // not meet the documented type requirements for a WriteHandler.
728  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
729 
730  return this->get_service().async_send(this->get_implementation(),
731  buffers, 0, ASIO_MOVE_CAST(WriteHandler)(handler));
732  }
733 
735 
762  template <typename MutableBufferSequence>
763  std::size_t read_some(const MutableBufferSequence& buffers)
764  {
765  asio::error_code ec;
766  std::size_t s = this->get_service().receive(
767  this->get_implementation(), buffers, 0, ec);
768  asio::detail::throw_error(ec, "read_some");
769  return s;
770  }
771 
773 
789  template <typename MutableBufferSequence>
790  std::size_t read_some(const MutableBufferSequence& buffers,
791  asio::error_code& ec)
792  {
793  return this->get_service().receive(
794  this->get_implementation(), buffers, 0, ec);
795  }
796 
798 
833  template <typename MutableBufferSequence, typename ReadHandler>
834  ASIO_INITFN_RESULT_TYPE(ReadHandler,
835  void (asio::error_code, std::size_t))
836  async_read_some(const MutableBufferSequence& buffers,
837  ASIO_MOVE_ARG(ReadHandler) handler)
838  {
839  // If you get an error on the following line it means that your handler does
840  // not meet the documented type requirements for a ReadHandler.
841  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
842 
843  return this->get_service().async_receive(this->get_implementation(),
844  buffers, 0, ASIO_MOVE_CAST(ReadHandler)(handler));
845  }
846 };
847 
848 } // namespace asio
849 
851 
852 #endif // ASIO_BASIC_STREAM_SOCKET_HPP
int message_flags
Bitmask type for flags that can be passed to send and receive operations.
Definition: socket_base.hpp:53
std::size_t receive(const MutableBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec)
Receive some data on a connected socket.
basic_stream_socket(asio::io_service &io_service)
Construct a basic_stream_socket without opening it.
StreamSocketService::native_handle_type native_type
void throw_error(const asio::error_code &err)
Definition: throw_error.hpp:31
basic_stream_socket(asio::io_service &io_service, const protocol_type &protocol, const native_handle_type &native_socket)
Construct a basic_stream_socket on an existing native socket.
Provides core I/O functionality.
Definition: io_service.hpp:184
ASIO_MOVE_ARG(ReadHandler) handler)
service_type & get_service()
Get the service associated with the I/O object.
#define ASIO_MOVE_CAST2(type1, type2)
Definition: config.hpp:139
ASIO_INITFN_RESULT_TYPE(WriteHandler, void(asio::error_code, std::size_t)) async_send(const ConstBufferSequence &buffers
Start an asynchronous send.
SocketService & s
Definition: connect.hpp:521
Provides stream-oriented socket functionality.
std::size_t receive(const MutableBufferSequence &buffers)
Receive some data on the socket.
socket_base::message_flags flags
std::size_t send(const ConstBufferSequence &buffers)
Send some data on the socket.
std::size_t read_some(const MutableBufferSequence &buffers)
Read some data from the socket.
const MutableBufferSequence & buffers
Definition: read.hpp:521
#define ASIO_READ_HANDLER_CHECK(handler_type, handler)
std::size_t send(const ConstBufferSequence &buffers, socket_base::message_flags flags)
Send some data on the socket.
implementation_type & get_implementation()
Get the underlying implementation of the I/O object.
basic_stream_socket(asio::io_service &io_service, const endpoint_type &endpoint)
Class to represent an error code value.
Definition: error_code.hpp:80
std::size_t receive(const MutableBufferSequence &buffers, socket_base::message_flags flags)
Receive some data on the socket.
Protocol protocol_type
The protocol type.
socket_base::message_flags ASIO_MOVE_ARG(ReadHandler) handler)
Provides socket functionality.
std::size_t read_some(const MutableBufferSequence &buffers, asio::error_code &ec)
Read some data from the socket.
std::size_t write_some(const ConstBufferSequence &buffers, asio::error_code &ec)
Write some data to the socket.
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
StreamSocketService::native_handle_type native_handle_type
The native representation of a socket.
#define ASIO_WRITE_HANDLER_CHECK(handler_type, handler)
std::size_t send(const ConstBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec)
Send some data on the socket.
Protocol::endpoint endpoint_type
The endpoint type.
ASIO_MOVE_ARG(WriteHandler) handler)
socket_base::message_flags ASIO_MOVE_ARG(WriteHandler) handler)
std::size_t write_some(const ConstBufferSequence &buffers)
Write some data to the socket.
basic_stream_socket(asio::io_service &io_service, const protocol_type &protocol)
Construct and open a basic_stream_socket.