Realistic 3D camera system
3D camera system components
basic_raw_socket.hpp
Go to the documentation of this file.
1 //
2 // basic_raw_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_RAW_SOCKET_HPP
12 #define ASIO_BASIC_RAW_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/basic_socket.hpp"
24 #include "asio/error.hpp"
26 
28 
29 namespace asio {
30 
32 
40 template <typename Protocol,
41  typename RawSocketService = raw_socket_service<Protocol> >
43  : public basic_socket<Protocol, RawSocketService>
44 {
45 public:
48  typedef typename RawSocketService::native_handle_type native_type;
49 
51  typedef typename RawSocketService::native_handle_type native_handle_type;
52 
54  typedef Protocol protocol_type;
55 
57  typedef typename Protocol::endpoint endpoint_type;
58 
60 
69  : basic_socket<Protocol, RawSocketService>(io_service)
70  {
71  }
72 
74 
86  const protocol_type& protocol)
87  : basic_socket<Protocol, RawSocketService>(io_service, protocol)
88  {
89  }
90 
93 
108  const endpoint_type& endpoint)
109  : basic_socket<Protocol, RawSocketService>(io_service, endpoint)
110  {
111  }
112 
114 
129  const protocol_type& protocol, const native_handle_type& native_socket)
130  : basic_socket<Protocol, RawSocketService>(
131  io_service, protocol, native_socket)
132  {
133  }
134 
135 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
136 
149  {
150  }
151 
153 
162  basic_raw_socket& operator=(basic_raw_socket&& other)
163  {
166  return *this;
167  }
168 
170 
179  template <typename Protocol1, typename RawSocketService1>
181  typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
184  Protocol1, RawSocketService1>)(other))
185  {
186  }
187 
189 
198  template <typename Protocol1, typename RawSocketService1>
200  basic_raw_socket>::type& operator=(
202  {
205  Protocol1, RawSocketService1>)(other));
206  return *this;
207  }
208 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
209 
211 
231  template <typename ConstBufferSequence>
232  std::size_t send(const ConstBufferSequence& buffers)
233  {
234  asio::error_code ec;
235  std::size_t s = this->get_service().send(
236  this->get_implementation(), buffers, 0, ec);
237  asio::detail::throw_error(ec, "send");
238  return s;
239  }
240 
242 
257  template <typename ConstBufferSequence>
258  std::size_t send(const ConstBufferSequence& buffers,
260  {
261  asio::error_code ec;
262  std::size_t s = this->get_service().send(
263  this->get_implementation(), buffers, flags, ec);
264  asio::detail::throw_error(ec, "send");
265  return s;
266  }
267 
269 
284  template <typename ConstBufferSequence>
285  std::size_t send(const ConstBufferSequence& buffers,
287  {
288  return this->get_service().send(
289  this->get_implementation(), buffers, flags, ec);
290  }
291 
293 
327  template <typename ConstBufferSequence, typename WriteHandler>
328  ASIO_INITFN_RESULT_TYPE(WriteHandler,
329  void (asio::error_code, std::size_t))
330  async_send(const ConstBufferSequence& buffers,
331  ASIO_MOVE_ARG(WriteHandler) handler)
332  {
333  // If you get an error on the following line it means that your handler does
334  // not meet the documented type requirements for a WriteHandler.
335  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
336 
337  return this->get_service().async_send(this->get_implementation(),
338  buffers, 0, ASIO_MOVE_CAST(WriteHandler)(handler));
339  }
340 
342 
369  template <typename ConstBufferSequence, typename WriteHandler>
370  ASIO_INITFN_RESULT_TYPE(WriteHandler,
371  void (asio::error_code, std::size_t))
372  async_send(const ConstBufferSequence& buffers,
374  ASIO_MOVE_ARG(WriteHandler) handler)
375  {
376  // If you get an error on the following line it means that your handler does
377  // not meet the documented type requirements for a WriteHandler.
378  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
379 
380  return this->get_service().async_send(this->get_implementation(),
381  buffers, flags, ASIO_MOVE_CAST(WriteHandler)(handler));
382  }
383 
385 
409  template <typename ConstBufferSequence>
410  std::size_t send_to(const ConstBufferSequence& buffers,
411  const endpoint_type& destination)
412  {
413  asio::error_code ec;
414  std::size_t s = this->get_service().send_to(
415  this->get_implementation(), buffers, destination, 0, ec);
416  asio::detail::throw_error(ec, "send_to");
417  return s;
418  }
419 
421 
436  template <typename ConstBufferSequence>
437  std::size_t send_to(const ConstBufferSequence& buffers,
438  const endpoint_type& destination, socket_base::message_flags flags)
439  {
440  asio::error_code ec;
441  std::size_t s = this->get_service().send_to(
442  this->get_implementation(), buffers, destination, flags, ec);
443  asio::detail::throw_error(ec, "send_to");
444  return s;
445  }
446 
448 
463  template <typename ConstBufferSequence>
464  std::size_t send_to(const ConstBufferSequence& buffers,
465  const endpoint_type& destination, socket_base::message_flags flags,
466  asio::error_code& ec)
467  {
468  return this->get_service().send_to(this->get_implementation(),
469  buffers, destination, flags, ec);
470  }
471 
473 
509  template <typename ConstBufferSequence, typename WriteHandler>
510  ASIO_INITFN_RESULT_TYPE(WriteHandler,
511  void (asio::error_code, std::size_t))
512  async_send_to(const ConstBufferSequence& buffers,
513  const endpoint_type& destination,
514  ASIO_MOVE_ARG(WriteHandler) handler)
515  {
516  // If you get an error on the following line it means that your handler does
517  // not meet the documented type requirements for a WriteHandler.
518  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
519 
520  return this->get_service().async_send_to(this->get_implementation(),
521  buffers, destination, 0, ASIO_MOVE_CAST(WriteHandler)(handler));
522  }
523 
525 
551  template <typename ConstBufferSequence, typename WriteHandler>
552  ASIO_INITFN_RESULT_TYPE(WriteHandler,
553  void (asio::error_code, std::size_t))
554  async_send_to(const ConstBufferSequence& buffers,
555  const endpoint_type& destination, socket_base::message_flags flags,
556  ASIO_MOVE_ARG(WriteHandler) handler)
557  {
558  // If you get an error on the following line it means that your handler does
559  // not meet the documented type requirements for a WriteHandler.
560  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
561 
562  return this->get_service().async_send_to(
563  this->get_implementation(), buffers, destination, flags,
564  ASIO_MOVE_CAST(WriteHandler)(handler));
565  }
566 
568 
591  template <typename MutableBufferSequence>
592  std::size_t receive(const MutableBufferSequence& buffers)
593  {
594  asio::error_code ec;
595  std::size_t s = this->get_service().receive(
596  this->get_implementation(), buffers, 0, ec);
597  asio::detail::throw_error(ec, "receive");
598  return s;
599  }
600 
602 
619  template <typename MutableBufferSequence>
620  std::size_t receive(const MutableBufferSequence& buffers,
622  {
623  asio::error_code ec;
624  std::size_t s = this->get_service().receive(
625  this->get_implementation(), buffers, flags, ec);
626  asio::detail::throw_error(ec, "receive");
627  return s;
628  }
629 
631 
648  template <typename MutableBufferSequence>
649  std::size_t receive(const MutableBufferSequence& buffers,
651  {
652  return this->get_service().receive(
653  this->get_implementation(), buffers, flags, ec);
654  }
655 
657 
692  template <typename MutableBufferSequence, typename ReadHandler>
693  ASIO_INITFN_RESULT_TYPE(ReadHandler,
694  void (asio::error_code, std::size_t))
695  async_receive(const MutableBufferSequence& buffers,
696  ASIO_MOVE_ARG(ReadHandler) handler)
697  {
698  // If you get an error on the following line it means that your handler does
699  // not meet the documented type requirements for a ReadHandler.
700  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
701 
702  return this->get_service().async_receive(this->get_implementation(),
703  buffers, 0, ASIO_MOVE_CAST(ReadHandler)(handler));
704  }
705 
707 
734  template <typename MutableBufferSequence, typename ReadHandler>
735  ASIO_INITFN_RESULT_TYPE(ReadHandler,
736  void (asio::error_code, std::size_t))
737  async_receive(const MutableBufferSequence& buffers,
739  ASIO_MOVE_ARG(ReadHandler) handler)
740  {
741  // If you get an error on the following line it means that your handler does
742  // not meet the documented type requirements for a ReadHandler.
743  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
744 
745  return this->get_service().async_receive(this->get_implementation(),
746  buffers, flags, ASIO_MOVE_CAST(ReadHandler)(handler));
747  }
748 
750 
775  template <typename MutableBufferSequence>
776  std::size_t receive_from(const MutableBufferSequence& buffers,
777  endpoint_type& sender_endpoint)
778  {
779  asio::error_code ec;
780  std::size_t s = this->get_service().receive_from(
781  this->get_implementation(), buffers, sender_endpoint, 0, ec);
782  asio::detail::throw_error(ec, "receive_from");
783  return s;
784  }
785 
787 
802  template <typename MutableBufferSequence>
803  std::size_t receive_from(const MutableBufferSequence& buffers,
804  endpoint_type& sender_endpoint, socket_base::message_flags flags)
805  {
806  asio::error_code ec;
807  std::size_t s = this->get_service().receive_from(
808  this->get_implementation(), buffers, sender_endpoint, flags, ec);
809  asio::detail::throw_error(ec, "receive_from");
810  return s;
811  }
812 
814 
829  template <typename MutableBufferSequence>
830  std::size_t receive_from(const MutableBufferSequence& buffers,
831  endpoint_type& sender_endpoint, socket_base::message_flags flags,
832  asio::error_code& ec)
833  {
834  return this->get_service().receive_from(this->get_implementation(),
835  buffers, sender_endpoint, flags, ec);
836  }
837 
839 
874  template <typename MutableBufferSequence, typename ReadHandler>
875  ASIO_INITFN_RESULT_TYPE(ReadHandler,
876  void (asio::error_code, std::size_t))
877  async_receive_from(const MutableBufferSequence& buffers,
878  endpoint_type& sender_endpoint,
879  ASIO_MOVE_ARG(ReadHandler) handler)
880  {
881  // If you get an error on the following line it means that your handler does
882  // not meet the documented type requirements for a ReadHandler.
883  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
884 
885  return this->get_service().async_receive_from(
886  this->get_implementation(), buffers, sender_endpoint, 0,
887  ASIO_MOVE_CAST(ReadHandler)(handler));
888  }
889 
891 
919  template <typename MutableBufferSequence, typename ReadHandler>
920  ASIO_INITFN_RESULT_TYPE(ReadHandler,
921  void (asio::error_code, std::size_t))
922  async_receive_from(const MutableBufferSequence& buffers,
923  endpoint_type& sender_endpoint, socket_base::message_flags flags,
924  ASIO_MOVE_ARG(ReadHandler) handler)
925  {
926  // If you get an error on the following line it means that your handler does
927  // not meet the documented type requirements for a ReadHandler.
928  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
929 
930  return this->get_service().async_receive_from(
931  this->get_implementation(), buffers, sender_endpoint, flags,
932  ASIO_MOVE_CAST(ReadHandler)(handler));
933  }
934 };
935 
936 } // namespace asio
937 
939 
940 #endif // ASIO_BASIC_RAW_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 send(const ConstBufferSequence &buffers)
Send some data on a connected socket.
basic_raw_socket(asio::io_service &io_service, const protocol_type &protocol)
Construct and open a basic_raw_socket.
void throw_error(const asio::error_code &err)
Definition: throw_error.hpp:31
ASIO_INITFN_RESULT_TYPE(WriteHandler, void(asio::error_code, std::size_t)) async_send(const ConstBufferSequence &buffers
Start an asynchronous send on a connected socket.
Provides core I/O functionality.
Definition: io_service.hpp:184
service_type & get_service()
Get the service associated with the I/O object.
#define ASIO_MOVE_CAST2(type1, type2)
Definition: config.hpp:139
SocketService & s
Definition: connect.hpp:521
std::size_t send_to(const ConstBufferSequence &buffers, const endpoint_type &destination)
Send raw data to the specified endpoint.
basic_raw_socket(asio::io_service &io_service)
Construct a basic_raw_socket without opening it.
Protocol protocol_type
The protocol type.
RawSocketService::native_handle_type native_handle_type
The native representation of a socket.
const endpoint_type ASIO_MOVE_ARG(WriteHandler) handler)
std::size_t receive_from(const MutableBufferSequence &buffers, endpoint_type &sender_endpoint, socket_base::message_flags flags)
Receive raw data with the endpoint of the sender.
std::size_t receive_from(const MutableBufferSequence &buffers, endpoint_type &sender_endpoint)
Receive raw data with the endpoint of the sender.
const endpoint_type socket_base::message_flags ASIO_MOVE_ARG(WriteHandler) handler)
const MutableBufferSequence & buffers
Definition: read.hpp:521
endpoint_type ASIO_MOVE_ARG(ReadHandler) handler)
std::size_t receive(const MutableBufferSequence &buffers)
Receive some data on a connected socket.
#define ASIO_READ_HANDLER_CHECK(handler_type, handler)
const endpoint_type & destination
ASIO_MOVE_ARG(ReadHandler) handler)
RawSocketService::native_handle_type native_type
socket_base::message_flags flags
implementation_type & get_implementation()
Get the underlying implementation of the I/O object.
endpoint_type & sender_endpoint
std::size_t receive(const MutableBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec)
Receive some data on a connected socket.
socket_base::message_flags ASIO_MOVE_ARG(WriteHandler) handler)
Class to represent an error code value.
Definition: error_code.hpp:80
basic_raw_socket(asio::io_service &io_service, const protocol_type &protocol, const native_handle_type &native_socket)
Construct a basic_raw_socket on an existing native socket.
std::size_t send_to(const ConstBufferSequence &buffers, const endpoint_type &destination, socket_base::message_flags flags)
Send raw data to the specified endpoint.
std::size_t receive(const MutableBufferSequence &buffers, socket_base::message_flags flags)
Receive some data on a connected socket.
socket_base::message_flags ASIO_MOVE_ARG(ReadHandler) handler)
Provides raw-oriented socket functionality.
std::size_t send_to(const ConstBufferSequence &buffers, const endpoint_type &destination, socket_base::message_flags flags, asio::error_code &ec)
Send raw data to the specified endpoint.
Protocol::endpoint endpoint_type
The endpoint type.
std::size_t receive_from(const MutableBufferSequence &buffers, endpoint_type &sender_endpoint, socket_base::message_flags flags, asio::error_code &ec)
Receive raw data with the endpoint of the sender.
basic_raw_socket(asio::io_service &io_service, const endpoint_type &endpoint)
Provides socket functionality.
ASIO_MOVE_ARG(WriteHandler) handler)
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
std::size_t send(const ConstBufferSequence &buffers, socket_base::message_flags flags)
Send some data on a connected socket.
std::size_t send(const ConstBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec)
Send some data on a connected socket.
#define ASIO_WRITE_HANDLER_CHECK(handler_type, handler)
endpoint_type socket_base::message_flags ASIO_MOVE_ARG(ReadHandler) handler)