Realistic 3D camera system
3D camera system components
basic_datagram_socket.hpp
Go to the documentation of this file.
1 //
2 // basic_datagram_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_DATAGRAM_SOCKET_HPP
12 #define ASIO_BASIC_DATAGRAM_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"
25 #include "asio/error.hpp"
26 
28 
29 namespace asio {
30 
32 
40 template <typename Protocol,
41  typename DatagramSocketService = datagram_socket_service<Protocol> >
43  : public basic_socket<Protocol, DatagramSocketService>
44 {
45 public:
48  typedef typename DatagramSocketService::native_handle_type native_type;
49 
51  typedef typename DatagramSocketService::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, DatagramSocketService>(io_service)
70  {
71  }
72 
74 
86  const protocol_type& protocol)
87  : basic_socket<Protocol, DatagramSocketService>(io_service, protocol)
88  {
89  }
90 
93 
108  const endpoint_type& endpoint)
109  : basic_socket<Protocol, DatagramSocketService>(io_service, endpoint)
110  {
111  }
112 
114 
129  const protocol_type& protocol, const native_handle_type& native_socket)
130  : basic_socket<Protocol, DatagramSocketService>(
131  io_service, protocol, native_socket)
132  {
133  }
134 
135 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
136 
149  {
150  }
151 
153 
163  basic_datagram_socket& operator=(basic_datagram_socket&& other)
164  {
167  return *this;
168  }
169 
172 
181  template <typename Protocol1, typename DatagramSocketService1>
184  typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
187  Protocol1, DatagramSocketService1>)(other))
188  {
189  }
190 
193 
203  template <typename Protocol1, typename DatagramSocketService1>
205  basic_datagram_socket>::type& operator=(
207  {
210  Protocol1, DatagramSocketService1>)(other));
211  return *this;
212  }
213 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
214 
216 
237  template <typename ConstBufferSequence>
238  std::size_t send(const ConstBufferSequence& buffers)
239  {
240  asio::error_code ec;
241  std::size_t s = this->get_service().send(
242  this->get_implementation(), buffers, 0, ec);
243  asio::detail::throw_error(ec, "send");
244  return s;
245  }
246 
248 
264  template <typename ConstBufferSequence>
265  std::size_t send(const ConstBufferSequence& buffers,
267  {
268  asio::error_code ec;
269  std::size_t s = this->get_service().send(
270  this->get_implementation(), buffers, flags, ec);
271  asio::detail::throw_error(ec, "send");
272  return s;
273  }
274 
276 
292  template <typename ConstBufferSequence>
293  std::size_t send(const ConstBufferSequence& buffers,
295  {
296  return this->get_service().send(
297  this->get_implementation(), buffers, flags, ec);
298  }
299 
301 
335  template <typename ConstBufferSequence, typename WriteHandler>
336  ASIO_INITFN_RESULT_TYPE(WriteHandler,
337  void (asio::error_code, std::size_t))
338  async_send(const ConstBufferSequence& buffers,
339  ASIO_MOVE_ARG(WriteHandler) handler)
340  {
341  // If you get an error on the following line it means that your handler does
342  // not meet the documented type requirements for a WriteHandler.
343  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
344 
345  return this->get_service().async_send(this->get_implementation(),
346  buffers, 0, ASIO_MOVE_CAST(WriteHandler)(handler));
347  }
348 
350 
377  template <typename ConstBufferSequence, typename WriteHandler>
378  ASIO_INITFN_RESULT_TYPE(WriteHandler,
379  void (asio::error_code, std::size_t))
380  async_send(const ConstBufferSequence& buffers,
382  ASIO_MOVE_ARG(WriteHandler) handler)
383  {
384  // If you get an error on the following line it means that your handler does
385  // not meet the documented type requirements for a WriteHandler.
386  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
387 
388  return this->get_service().async_send(this->get_implementation(),
389  buffers, flags, ASIO_MOVE_CAST(WriteHandler)(handler));
390  }
391 
393 
417  template <typename ConstBufferSequence>
418  std::size_t send_to(const ConstBufferSequence& buffers,
419  const endpoint_type& destination)
420  {
421  asio::error_code ec;
422  std::size_t s = this->get_service().send_to(
423  this->get_implementation(), buffers, destination, 0, ec);
424  asio::detail::throw_error(ec, "send_to");
425  return s;
426  }
427 
429 
444  template <typename ConstBufferSequence>
445  std::size_t send_to(const ConstBufferSequence& buffers,
446  const endpoint_type& destination, socket_base::message_flags flags)
447  {
448  asio::error_code ec;
449  std::size_t s = this->get_service().send_to(
450  this->get_implementation(), buffers, destination, flags, ec);
451  asio::detail::throw_error(ec, "send_to");
452  return s;
453  }
454 
456 
471  template <typename ConstBufferSequence>
472  std::size_t send_to(const ConstBufferSequence& buffers,
473  const endpoint_type& destination, socket_base::message_flags flags,
474  asio::error_code& ec)
475  {
476  return this->get_service().send_to(this->get_implementation(),
477  buffers, destination, flags, ec);
478  }
479 
481 
517  template <typename ConstBufferSequence, typename WriteHandler>
518  ASIO_INITFN_RESULT_TYPE(WriteHandler,
519  void (asio::error_code, std::size_t))
520  async_send_to(const ConstBufferSequence& buffers,
521  const endpoint_type& destination,
522  ASIO_MOVE_ARG(WriteHandler) handler)
523  {
524  // If you get an error on the following line it means that your handler does
525  // not meet the documented type requirements for a WriteHandler.
526  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
527 
528  return this->get_service().async_send_to(
529  this->get_implementation(), buffers, destination, 0,
530  ASIO_MOVE_CAST(WriteHandler)(handler));
531  }
532 
534 
560  template <typename ConstBufferSequence, typename WriteHandler>
561  ASIO_INITFN_RESULT_TYPE(WriteHandler,
562  void (asio::error_code, std::size_t))
563  async_send_to(const ConstBufferSequence& buffers,
564  const endpoint_type& destination, socket_base::message_flags flags,
565  ASIO_MOVE_ARG(WriteHandler) handler)
566  {
567  // If you get an error on the following line it means that your handler does
568  // not meet the documented type requirements for a WriteHandler.
569  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
570 
571  return this->get_service().async_send_to(
572  this->get_implementation(), buffers, destination, flags,
573  ASIO_MOVE_CAST(WriteHandler)(handler));
574  }
575 
577 
600  template <typename MutableBufferSequence>
601  std::size_t receive(const MutableBufferSequence& buffers)
602  {
603  asio::error_code ec;
604  std::size_t s = this->get_service().receive(
605  this->get_implementation(), buffers, 0, ec);
606  asio::detail::throw_error(ec, "receive");
607  return s;
608  }
609 
611 
628  template <typename MutableBufferSequence>
629  std::size_t receive(const MutableBufferSequence& buffers,
631  {
632  asio::error_code ec;
633  std::size_t s = this->get_service().receive(
634  this->get_implementation(), buffers, flags, ec);
635  asio::detail::throw_error(ec, "receive");
636  return s;
637  }
638 
640 
657  template <typename MutableBufferSequence>
658  std::size_t receive(const MutableBufferSequence& buffers,
660  {
661  return this->get_service().receive(
662  this->get_implementation(), buffers, flags, ec);
663  }
664 
666 
701  template <typename MutableBufferSequence, typename ReadHandler>
702  ASIO_INITFN_RESULT_TYPE(ReadHandler,
703  void (asio::error_code, std::size_t))
704  async_receive(const MutableBufferSequence& buffers,
705  ASIO_MOVE_ARG(ReadHandler) handler)
706  {
707  // If you get an error on the following line it means that your handler does
708  // not meet the documented type requirements for a ReadHandler.
709  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
710 
711  return this->get_service().async_receive(this->get_implementation(),
712  buffers, 0, ASIO_MOVE_CAST(ReadHandler)(handler));
713  }
714 
716 
743  template <typename MutableBufferSequence, typename ReadHandler>
744  ASIO_INITFN_RESULT_TYPE(ReadHandler,
745  void (asio::error_code, std::size_t))
746  async_receive(const MutableBufferSequence& buffers,
748  ASIO_MOVE_ARG(ReadHandler) handler)
749  {
750  // If you get an error on the following line it means that your handler does
751  // not meet the documented type requirements for a ReadHandler.
752  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
753 
754  return this->get_service().async_receive(this->get_implementation(),
755  buffers, flags, ASIO_MOVE_CAST(ReadHandler)(handler));
756  }
757 
759 
784  template <typename MutableBufferSequence>
785  std::size_t receive_from(const MutableBufferSequence& buffers,
786  endpoint_type& sender_endpoint)
787  {
788  asio::error_code ec;
789  std::size_t s = this->get_service().receive_from(
790  this->get_implementation(), buffers, sender_endpoint, 0, ec);
791  asio::detail::throw_error(ec, "receive_from");
792  return s;
793  }
794 
796 
811  template <typename MutableBufferSequence>
812  std::size_t receive_from(const MutableBufferSequence& buffers,
813  endpoint_type& sender_endpoint, socket_base::message_flags flags)
814  {
815  asio::error_code ec;
816  std::size_t s = this->get_service().receive_from(
817  this->get_implementation(), buffers, sender_endpoint, flags, ec);
818  asio::detail::throw_error(ec, "receive_from");
819  return s;
820  }
821 
823 
838  template <typename MutableBufferSequence>
839  std::size_t receive_from(const MutableBufferSequence& buffers,
840  endpoint_type& sender_endpoint, socket_base::message_flags flags,
841  asio::error_code& ec)
842  {
843  return this->get_service().receive_from(this->get_implementation(),
844  buffers, sender_endpoint, flags, ec);
845  }
846 
848 
883  template <typename MutableBufferSequence, typename ReadHandler>
884  ASIO_INITFN_RESULT_TYPE(ReadHandler,
885  void (asio::error_code, std::size_t))
886  async_receive_from(const MutableBufferSequence& buffers,
887  endpoint_type& sender_endpoint,
888  ASIO_MOVE_ARG(ReadHandler) handler)
889  {
890  // If you get an error on the following line it means that your handler does
891  // not meet the documented type requirements for a ReadHandler.
892  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
893 
894  return this->get_service().async_receive_from(
895  this->get_implementation(), buffers, sender_endpoint, 0,
896  ASIO_MOVE_CAST(ReadHandler)(handler));
897  }
898 
900 
928  template <typename MutableBufferSequence, typename ReadHandler>
929  ASIO_INITFN_RESULT_TYPE(ReadHandler,
930  void (asio::error_code, std::size_t))
931  async_receive_from(const MutableBufferSequence& buffers,
932  endpoint_type& sender_endpoint, socket_base::message_flags flags,
933  ASIO_MOVE_ARG(ReadHandler) handler)
934  {
935  // If you get an error on the following line it means that your handler does
936  // not meet the documented type requirements for a ReadHandler.
937  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
938 
939  return this->get_service().async_receive_from(
940  this->get_implementation(), buffers, sender_endpoint, flags,
941  ASIO_MOVE_CAST(ReadHandler)(handler));
942  }
943 };
944 
945 } // namespace asio
946 
948 
949 #endif // ASIO_BASIC_DATAGRAM_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.
endpoint_type ASIO_MOVE_ARG(ReadHandler) handler)
ASIO_MOVE_ARG(WriteHandler) handler)
void throw_error(const asio::error_code &err)
Definition: throw_error.hpp:31
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
std::size_t send_to(const ConstBufferSequence &buffers, const endpoint_type &destination, socket_base::message_flags flags, asio::error_code &ec)
Send a datagram to the specified endpoint.
socket_base::message_flags ASIO_MOVE_ARG(ReadHandler) handler)
SocketService & s
Definition: connect.hpp:521
const endpoint_type socket_base::message_flags ASIO_MOVE_ARG(WriteHandler) handler)
basic_datagram_socket(asio::io_service &io_service)
Construct a basic_datagram_socket without opening it.
std::size_t send_to(const ConstBufferSequence &buffers, const endpoint_type &destination)
Send a datagram to the specified endpoint.
Protocol protocol_type
The protocol type.
Protocol::endpoint endpoint_type
The endpoint type.
basic_datagram_socket(asio::io_service &io_service, const protocol_type &protocol)
Construct and open a basic_datagram_socket.
const MutableBufferSequence & buffers
Definition: read.hpp:521
#define ASIO_READ_HANDLER_CHECK(handler_type, handler)
socket_base::message_flags ASIO_MOVE_ARG(WriteHandler) handler)
Provides datagram-oriented socket functionality.
const endpoint_type ASIO_MOVE_ARG(WriteHandler) handler)
std::size_t send_to(const ConstBufferSequence &buffers, const endpoint_type &destination, socket_base::message_flags flags)
Send a datagram to the specified endpoint.
std::size_t send(const ConstBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec)
Send some data on a connected socket.
DatagramSocketService::native_handle_type native_type
implementation_type & get_implementation()
Get the underlying implementation of the I/O object.
std::size_t receive(const MutableBufferSequence &buffers)
Receive some data on a connected socket.
basic_datagram_socket(asio::io_service &io_service, const endpoint_type &endpoint)
Class to represent an error code value.
Definition: error_code.hpp:80
endpoint_type socket_base::message_flags ASIO_MOVE_ARG(ReadHandler) handler)
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.
std::size_t receive(const MutableBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec)
Receive some data on a connected socket.
Provides socket functionality.
std::size_t receive(const MutableBufferSequence &buffers, socket_base::message_flags flags)
Receive some data on a connected socket.
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
socket_base::message_flags flags
std::size_t receive_from(const MutableBufferSequence &buffers, endpoint_type &sender_endpoint, socket_base::message_flags flags, asio::error_code &ec)
Receive a datagram with the endpoint of the sender.
#define ASIO_WRITE_HANDLER_CHECK(handler_type, handler)
std::size_t receive_from(const MutableBufferSequence &buffers, endpoint_type &sender_endpoint, socket_base::message_flags flags)
Receive a datagram with the endpoint of the sender.
std::size_t send(const ConstBufferSequence &buffers, socket_base::message_flags flags)
Send some data on a connected socket.
DatagramSocketService::native_handle_type native_handle_type
The native representation of a socket.
basic_datagram_socket(asio::io_service &io_service, const protocol_type &protocol, const native_handle_type &native_socket)
Construct a basic_datagram_socket on an existing native socket.
std::size_t receive_from(const MutableBufferSequence &buffers, endpoint_type &sender_endpoint)
Receive a datagram with the endpoint of the sender.