]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/basic_datagram_socket.hpp
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / boost / boost / asio / basic_datagram_socket.hpp
1 //
2 // basic_datagram_socket.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2022 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 BOOST_ASIO_BASIC_DATAGRAM_SOCKET_HPP
12 #define BOOST_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 <boost/asio/detail/config.hpp>
19 #include <cstddef>
20 #include <boost/asio/basic_socket.hpp>
21 #include <boost/asio/detail/handler_type_requirements.hpp>
22 #include <boost/asio/detail/non_const_lvalue.hpp>
23 #include <boost/asio/detail/throw_error.hpp>
24 #include <boost/asio/detail/type_traits.hpp>
25 #include <boost/asio/error.hpp>
26
27 #include <boost/asio/detail/push_options.hpp>
28
29 namespace boost {
30 namespace asio {
31
32 #if !defined(BOOST_ASIO_BASIC_DATAGRAM_SOCKET_FWD_DECL)
33 #define BOOST_ASIO_BASIC_DATAGRAM_SOCKET_FWD_DECL
34
35 // Forward declaration with defaulted arguments.
36 template <typename Protocol, typename Executor = any_io_executor>
37 class basic_datagram_socket;
38
39 #endif // !defined(BOOST_ASIO_BASIC_DATAGRAM_SOCKET_FWD_DECL)
40
41 /// Provides datagram-oriented socket functionality.
42 /**
43 * The basic_datagram_socket class template provides asynchronous and blocking
44 * datagram-oriented socket functionality.
45 *
46 * @par Thread Safety
47 * @e Distinct @e objects: Safe.@n
48 * @e Shared @e objects: Unsafe.
49 *
50 * Synchronous @c send, @c send_to, @c receive, @c receive_from, and @c connect
51 * operations are thread safe with respect to each other, if the underlying
52 * operating system calls are also thread safe. This means that it is permitted
53 * to perform concurrent calls to these synchronous operations on a single
54 * socket object. Other synchronous operations, such as @c open or @c close, are
55 * not thread safe.
56 */
57 template <typename Protocol, typename Executor>
58 class basic_datagram_socket
59 : public basic_socket<Protocol, Executor>
60 {
61 public:
62 /// The type of the executor associated with the object.
63 typedef Executor executor_type;
64
65 /// Rebinds the socket type to another executor.
66 template <typename Executor1>
67 struct rebind_executor
68 {
69 /// The socket type when rebound to the specified executor.
70 typedef basic_datagram_socket<Protocol, Executor1> other;
71 };
72
73 /// The native representation of a socket.
74 #if defined(GENERATING_DOCUMENTATION)
75 typedef implementation_defined native_handle_type;
76 #else
77 typedef typename basic_socket<Protocol,
78 Executor>::native_handle_type native_handle_type;
79 #endif
80
81 /// The protocol type.
82 typedef Protocol protocol_type;
83
84 /// The endpoint type.
85 typedef typename Protocol::endpoint endpoint_type;
86
87 /// Construct a basic_datagram_socket without opening it.
88 /**
89 * This constructor creates a datagram socket without opening it. The open()
90 * function must be called before data can be sent or received on the socket.
91 *
92 * @param ex The I/O executor that the socket will use, by default, to
93 * dispatch handlers for any asynchronous operations performed on the socket.
94 */
95 explicit basic_datagram_socket(const executor_type& ex)
96 : basic_socket<Protocol, Executor>(ex)
97 {
98 }
99
100 /// Construct a basic_datagram_socket without opening it.
101 /**
102 * This constructor creates a datagram socket without opening it. The open()
103 * function must be called before data can be sent or received on the socket.
104 *
105 * @param context An execution context which provides the I/O executor that
106 * the socket will use, by default, to dispatch handlers for any asynchronous
107 * operations performed on the socket.
108 */
109 template <typename ExecutionContext>
110 explicit basic_datagram_socket(ExecutionContext& context,
111 typename constraint<
112 is_convertible<ExecutionContext&, execution_context&>::value
113 >::type = 0)
114 : basic_socket<Protocol, Executor>(context)
115 {
116 }
117
118 /// Construct and open a basic_datagram_socket.
119 /**
120 * This constructor creates and opens a datagram socket.
121 *
122 * @param ex The I/O executor that the socket will use, by default, to
123 * dispatch handlers for any asynchronous operations performed on the socket.
124 *
125 * @param protocol An object specifying protocol parameters to be used.
126 *
127 * @throws boost::system::system_error Thrown on failure.
128 */
129 basic_datagram_socket(const executor_type& ex, const protocol_type& protocol)
130 : basic_socket<Protocol, Executor>(ex, protocol)
131 {
132 }
133
134 /// Construct and open a basic_datagram_socket.
135 /**
136 * This constructor creates and opens a datagram socket.
137 *
138 * @param context An execution context which provides the I/O executor that
139 * the socket will use, by default, to dispatch handlers for any asynchronous
140 * operations performed on the socket.
141 *
142 * @param protocol An object specifying protocol parameters to be used.
143 *
144 * @throws boost::system::system_error Thrown on failure.
145 */
146 template <typename ExecutionContext>
147 basic_datagram_socket(ExecutionContext& context,
148 const protocol_type& protocol,
149 typename constraint<
150 is_convertible<ExecutionContext&, execution_context&>::value,
151 defaulted_constraint
152 >::type = defaulted_constraint())
153 : basic_socket<Protocol, Executor>(context, protocol)
154 {
155 }
156
157 /// Construct a basic_datagram_socket, opening it and binding it to the given
158 /// local endpoint.
159 /**
160 * This constructor creates a datagram socket and automatically opens it bound
161 * to the specified endpoint on the local machine. The protocol used is the
162 * protocol associated with the given endpoint.
163 *
164 * @param ex The I/O executor that the socket will use, by default, to
165 * dispatch handlers for any asynchronous operations performed on the socket.
166 *
167 * @param endpoint An endpoint on the local machine to which the datagram
168 * socket will be bound.
169 *
170 * @throws boost::system::system_error Thrown on failure.
171 */
172 basic_datagram_socket(const executor_type& ex, const endpoint_type& endpoint)
173 : basic_socket<Protocol, Executor>(ex, endpoint)
174 {
175 }
176
177 /// Construct a basic_datagram_socket, opening it and binding it to the given
178 /// local endpoint.
179 /**
180 * This constructor creates a datagram socket and automatically opens it bound
181 * to the specified endpoint on the local machine. The protocol used is the
182 * protocol associated with the given endpoint.
183 *
184 * @param context An execution context which provides the I/O executor that
185 * the socket will use, by default, to dispatch handlers for any asynchronous
186 * operations performed on the socket.
187 *
188 * @param endpoint An endpoint on the local machine to which the datagram
189 * socket will be bound.
190 *
191 * @throws boost::system::system_error Thrown on failure.
192 */
193 template <typename ExecutionContext>
194 basic_datagram_socket(ExecutionContext& context,
195 const endpoint_type& endpoint,
196 typename constraint<
197 is_convertible<ExecutionContext&, execution_context&>::value
198 >::type = 0)
199 : basic_socket<Protocol, Executor>(context, endpoint)
200 {
201 }
202
203 /// Construct a basic_datagram_socket on an existing native socket.
204 /**
205 * This constructor creates a datagram socket object to hold an existing
206 * native socket.
207 *
208 * @param ex The I/O executor that the socket will use, by default, to
209 * dispatch handlers for any asynchronous operations performed on the socket.
210 *
211 * @param protocol An object specifying protocol parameters to be used.
212 *
213 * @param native_socket The new underlying socket implementation.
214 *
215 * @throws boost::system::system_error Thrown on failure.
216 */
217 basic_datagram_socket(const executor_type& ex,
218 const protocol_type& protocol, const native_handle_type& native_socket)
219 : basic_socket<Protocol, Executor>(ex, protocol, native_socket)
220 {
221 }
222
223 /// Construct a basic_datagram_socket on an existing native socket.
224 /**
225 * This constructor creates a datagram socket object to hold an existing
226 * native socket.
227 *
228 * @param context An execution context which provides the I/O executor that
229 * the socket will use, by default, to dispatch handlers for any asynchronous
230 * operations performed on the socket.
231 *
232 * @param protocol An object specifying protocol parameters to be used.
233 *
234 * @param native_socket The new underlying socket implementation.
235 *
236 * @throws boost::system::system_error Thrown on failure.
237 */
238 template <typename ExecutionContext>
239 basic_datagram_socket(ExecutionContext& context,
240 const protocol_type& protocol, const native_handle_type& native_socket,
241 typename constraint<
242 is_convertible<ExecutionContext&, execution_context&>::value
243 >::type = 0)
244 : basic_socket<Protocol, Executor>(context, protocol, native_socket)
245 {
246 }
247
248 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
249 /// Move-construct a basic_datagram_socket from another.
250 /**
251 * This constructor moves a datagram socket from one object to another.
252 *
253 * @param other The other basic_datagram_socket object from which the move
254 * will occur.
255 *
256 * @note Following the move, the moved-from object is in the same state as if
257 * constructed using the @c basic_datagram_socket(const executor_type&)
258 * constructor.
259 */
260 basic_datagram_socket(basic_datagram_socket&& other) BOOST_ASIO_NOEXCEPT
261 : basic_socket<Protocol, Executor>(std::move(other))
262 {
263 }
264
265 /// Move-assign a basic_datagram_socket from another.
266 /**
267 * This assignment operator moves a datagram socket from one object to
268 * another.
269 *
270 * @param other The other basic_datagram_socket object from which the move
271 * will occur.
272 *
273 * @note Following the move, the moved-from object is in the same state as if
274 * constructed using the @c basic_datagram_socket(const executor_type&)
275 * constructor.
276 */
277 basic_datagram_socket& operator=(basic_datagram_socket&& other)
278 {
279 basic_socket<Protocol, Executor>::operator=(std::move(other));
280 return *this;
281 }
282
283 /// Move-construct a basic_datagram_socket from a socket of another protocol
284 /// type.
285 /**
286 * This constructor moves a datagram socket from one object to another.
287 *
288 * @param other The other basic_datagram_socket object from which the move
289 * will occur.
290 *
291 * @note Following the move, the moved-from object is in the same state as if
292 * constructed using the @c basic_datagram_socket(const executor_type&)
293 * constructor.
294 */
295 template <typename Protocol1, typename Executor1>
296 basic_datagram_socket(basic_datagram_socket<Protocol1, Executor1>&& other,
297 typename constraint<
298 is_convertible<Protocol1, Protocol>::value
299 && is_convertible<Executor1, Executor>::value
300 >::type = 0)
301 : basic_socket<Protocol, Executor>(std::move(other))
302 {
303 }
304
305 /// Move-assign a basic_datagram_socket from a socket of another protocol
306 /// type.
307 /**
308 * This assignment operator moves a datagram socket from one object to
309 * another.
310 *
311 * @param other The other basic_datagram_socket object from which the move
312 * will occur.
313 *
314 * @note Following the move, the moved-from object is in the same state as if
315 * constructed using the @c basic_datagram_socket(const executor_type&)
316 * constructor.
317 */
318 template <typename Protocol1, typename Executor1>
319 typename constraint<
320 is_convertible<Protocol1, Protocol>::value
321 && is_convertible<Executor1, Executor>::value,
322 basic_datagram_socket&
323 >::type operator=(basic_datagram_socket<Protocol1, Executor1>&& other)
324 {
325 basic_socket<Protocol, Executor>::operator=(std::move(other));
326 return *this;
327 }
328 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
329
330 /// Destroys the socket.
331 /**
332 * This function destroys the socket, cancelling any outstanding asynchronous
333 * operations associated with the socket as if by calling @c cancel.
334 */
335 ~basic_datagram_socket()
336 {
337 }
338
339 /// Send some data on a connected socket.
340 /**
341 * This function is used to send data on the datagram socket. The function
342 * call will block until the data has been sent successfully or an error
343 * occurs.
344 *
345 * @param buffers One ore more data buffers to be sent on the socket.
346 *
347 * @returns The number of bytes sent.
348 *
349 * @throws boost::system::system_error Thrown on failure.
350 *
351 * @note The send operation can only be used with a connected socket. Use
352 * the send_to function to send data on an unconnected datagram socket.
353 *
354 * @par Example
355 * To send a single data buffer use the @ref buffer function as follows:
356 * @code socket.send(boost::asio::buffer(data, size)); @endcode
357 * See the @ref buffer documentation for information on sending multiple
358 * buffers in one go, and how to use it with arrays, boost::array or
359 * std::vector.
360 */
361 template <typename ConstBufferSequence>
362 std::size_t send(const ConstBufferSequence& buffers)
363 {
364 boost::system::error_code ec;
365 std::size_t s = this->impl_.get_service().send(
366 this->impl_.get_implementation(), buffers, 0, ec);
367 boost::asio::detail::throw_error(ec, "send");
368 return s;
369 }
370
371 /// Send some data on a connected socket.
372 /**
373 * This function is used to send data on the datagram socket. The function
374 * call will block until the data has been sent successfully or an error
375 * occurs.
376 *
377 * @param buffers One ore more data buffers to be sent on the socket.
378 *
379 * @param flags Flags specifying how the send call is to be made.
380 *
381 * @returns The number of bytes sent.
382 *
383 * @throws boost::system::system_error Thrown on failure.
384 *
385 * @note The send operation can only be used with a connected socket. Use
386 * the send_to function to send data on an unconnected datagram socket.
387 */
388 template <typename ConstBufferSequence>
389 std::size_t send(const ConstBufferSequence& buffers,
390 socket_base::message_flags flags)
391 {
392 boost::system::error_code ec;
393 std::size_t s = this->impl_.get_service().send(
394 this->impl_.get_implementation(), buffers, flags, ec);
395 boost::asio::detail::throw_error(ec, "send");
396 return s;
397 }
398
399 /// Send some data on a connected socket.
400 /**
401 * This function is used to send data on the datagram socket. The function
402 * call will block until the data has been sent successfully or an error
403 * occurs.
404 *
405 * @param buffers One or more data buffers to be sent on the socket.
406 *
407 * @param flags Flags specifying how the send call is to be made.
408 *
409 * @param ec Set to indicate what error occurred, if any.
410 *
411 * @returns The number of bytes sent.
412 *
413 * @note The send operation can only be used with a connected socket. Use
414 * the send_to function to send data on an unconnected datagram socket.
415 */
416 template <typename ConstBufferSequence>
417 std::size_t send(const ConstBufferSequence& buffers,
418 socket_base::message_flags flags, boost::system::error_code& ec)
419 {
420 return this->impl_.get_service().send(
421 this->impl_.get_implementation(), buffers, flags, ec);
422 }
423
424 /// Start an asynchronous send on a connected socket.
425 /**
426 * This function is used to asynchronously send data on the datagram socket.
427 * It is an initiating function for an @ref asynchronous_operation, and always
428 * returns immediately.
429 *
430 * @param buffers One or more data buffers to be sent on the socket. Although
431 * the buffers object may be copied as necessary, ownership of the underlying
432 * memory blocks is retained by the caller, which must guarantee that they
433 * remain valid until the completion handler is called.
434 *
435 * @param token The @ref completion_token that will be used to produce a
436 * completion handler, which will be called when the send completes. Potential
437 * completion tokens include @ref use_future, @ref use_awaitable, @ref
438 * yield_context, or a function object with the correct completion signature.
439 * The function signature of the completion handler must be:
440 * @code void handler(
441 * const boost::system::error_code& error, // Result of operation.
442 * std::size_t bytes_transferred // Number of bytes sent.
443 * ); @endcode
444 * Regardless of whether the asynchronous operation completes immediately or
445 * not, the completion handler will not be invoked from within this function.
446 * On immediate completion, invocation of the handler will be performed in a
447 * manner equivalent to using boost::asio::post().
448 *
449 * @par Completion Signature
450 * @code void(boost::system::error_code, std::size_t) @endcode
451 *
452 * @note The async_send operation can only be used with a connected socket.
453 * Use the async_send_to function to send data on an unconnected datagram
454 * socket.
455 *
456 * @par Example
457 * To send a single data buffer use the @ref buffer function as follows:
458 * @code
459 * socket.async_send(boost::asio::buffer(data, size), handler);
460 * @endcode
461 * See the @ref buffer documentation for information on sending multiple
462 * buffers in one go, and how to use it with arrays, boost::array or
463 * std::vector.
464 *
465 * @par Per-Operation Cancellation
466 * On POSIX or Windows operating systems, this asynchronous operation supports
467 * cancellation for the following boost::asio::cancellation_type values:
468 *
469 * @li @c cancellation_type::terminal
470 *
471 * @li @c cancellation_type::partial
472 *
473 * @li @c cancellation_type::total
474 */
475 template <typename ConstBufferSequence,
476 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
477 std::size_t)) WriteToken
478 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
479 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
480 void (boost::system::error_code, std::size_t))
481 async_send(const ConstBufferSequence& buffers,
482 BOOST_ASIO_MOVE_ARG(WriteToken) token
483 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
484 {
485 return async_initiate<WriteToken,
486 void (boost::system::error_code, std::size_t)>(
487 initiate_async_send(this), token,
488 buffers, socket_base::message_flags(0));
489 }
490
491 /// Start an asynchronous send on a connected socket.
492 /**
493 * This function is used to asynchronously send data on the datagram socket.
494 * It is an initiating function for an @ref asynchronous_operation, and always
495 * returns immediately.
496 *
497 * @param buffers One or more data buffers to be sent on the socket. Although
498 * the buffers object may be copied as necessary, ownership of the underlying
499 * memory blocks is retained by the caller, which must guarantee that they
500 * remain valid until the completion handler is called.
501 *
502 * @param flags Flags specifying how the send call is to be made.
503 *
504 * @param token The @ref completion_token that will be used to produce a
505 * completion handler, which will be called when the send completes. Potential
506 * completion tokens include @ref use_future, @ref use_awaitable, @ref
507 * yield_context, or a function object with the correct completion signature.
508 * The function signature of the completion handler must be:
509 * @code void handler(
510 * const boost::system::error_code& error, // Result of operation.
511 * std::size_t bytes_transferred // Number of bytes sent.
512 * ); @endcode
513 * Regardless of whether the asynchronous operation completes immediately or
514 * not, the completion handler will not be invoked from within this function.
515 * On immediate completion, invocation of the handler will be performed in a
516 * manner equivalent to using boost::asio::post().
517 *
518 * @par Completion Signature
519 * @code void(boost::system::error_code, std::size_t) @endcode
520 *
521 * @note The async_send operation can only be used with a connected socket.
522 * Use the async_send_to function to send data on an unconnected datagram
523 * socket.
524 *
525 * @par Per-Operation Cancellation
526 * On POSIX or Windows operating systems, this asynchronous operation supports
527 * cancellation for the following boost::asio::cancellation_type values:
528 *
529 * @li @c cancellation_type::terminal
530 *
531 * @li @c cancellation_type::partial
532 *
533 * @li @c cancellation_type::total
534 */
535 template <typename ConstBufferSequence,
536 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
537 std::size_t)) WriteToken
538 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
539 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
540 void (boost::system::error_code, std::size_t))
541 async_send(const ConstBufferSequence& buffers,
542 socket_base::message_flags flags,
543 BOOST_ASIO_MOVE_ARG(WriteToken) token
544 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
545 {
546 return async_initiate<WriteToken,
547 void (boost::system::error_code, std::size_t)>(
548 initiate_async_send(this), token, buffers, flags);
549 }
550
551 /// Send a datagram to the specified endpoint.
552 /**
553 * This function is used to send a datagram to the specified remote endpoint.
554 * The function call will block until the data has been sent successfully or
555 * an error occurs.
556 *
557 * @param buffers One or more data buffers to be sent to the remote endpoint.
558 *
559 * @param destination The remote endpoint to which the data will be sent.
560 *
561 * @returns The number of bytes sent.
562 *
563 * @throws boost::system::system_error Thrown on failure.
564 *
565 * @par Example
566 * To send a single data buffer use the @ref buffer function as follows:
567 * @code
568 * boost::asio::ip::udp::endpoint destination(
569 * boost::asio::ip::address::from_string("1.2.3.4"), 12345);
570 * socket.send_to(boost::asio::buffer(data, size), destination);
571 * @endcode
572 * See the @ref buffer documentation for information on sending multiple
573 * buffers in one go, and how to use it with arrays, boost::array or
574 * std::vector.
575 */
576 template <typename ConstBufferSequence>
577 std::size_t send_to(const ConstBufferSequence& buffers,
578 const endpoint_type& destination)
579 {
580 boost::system::error_code ec;
581 std::size_t s = this->impl_.get_service().send_to(
582 this->impl_.get_implementation(), buffers, destination, 0, ec);
583 boost::asio::detail::throw_error(ec, "send_to");
584 return s;
585 }
586
587 /// Send a datagram to the specified endpoint.
588 /**
589 * This function is used to send a datagram to the specified remote endpoint.
590 * The function call will block until the data has been sent successfully or
591 * an error occurs.
592 *
593 * @param buffers One or more data buffers to be sent to the remote endpoint.
594 *
595 * @param destination The remote endpoint to which the data will be sent.
596 *
597 * @param flags Flags specifying how the send call is to be made.
598 *
599 * @returns The number of bytes sent.
600 *
601 * @throws boost::system::system_error Thrown on failure.
602 */
603 template <typename ConstBufferSequence>
604 std::size_t send_to(const ConstBufferSequence& buffers,
605 const endpoint_type& destination, socket_base::message_flags flags)
606 {
607 boost::system::error_code ec;
608 std::size_t s = this->impl_.get_service().send_to(
609 this->impl_.get_implementation(), buffers, destination, flags, ec);
610 boost::asio::detail::throw_error(ec, "send_to");
611 return s;
612 }
613
614 /// Send a datagram to the specified endpoint.
615 /**
616 * This function is used to send a datagram to the specified remote endpoint.
617 * The function call will block until the data has been sent successfully or
618 * an error occurs.
619 *
620 * @param buffers One or more data buffers to be sent to the remote endpoint.
621 *
622 * @param destination The remote endpoint to which the data will be sent.
623 *
624 * @param flags Flags specifying how the send call is to be made.
625 *
626 * @param ec Set to indicate what error occurred, if any.
627 *
628 * @returns The number of bytes sent.
629 */
630 template <typename ConstBufferSequence>
631 std::size_t send_to(const ConstBufferSequence& buffers,
632 const endpoint_type& destination, socket_base::message_flags flags,
633 boost::system::error_code& ec)
634 {
635 return this->impl_.get_service().send_to(this->impl_.get_implementation(),
636 buffers, destination, flags, ec);
637 }
638
639 /// Start an asynchronous send.
640 /**
641 * This function is used to asynchronously send a datagram to the specified
642 * remote endpoint. It is an initiating function for an @ref
643 * asynchronous_operation, and always returns immediately.
644 *
645 * @param buffers One or more data buffers to be sent to the remote endpoint.
646 * Although the buffers object may be copied as necessary, ownership of the
647 * underlying memory blocks is retained by the caller, which must guarantee
648 * that they remain valid until the completion handler is called.
649 *
650 * @param destination The remote endpoint to which the data will be sent.
651 * Copies will be made of the endpoint as required.
652 *
653 * @param token The @ref completion_token that will be used to produce a
654 * completion handler, which will be called when the send completes. Potential
655 * completion tokens include @ref use_future, @ref use_awaitable, @ref
656 * yield_context, or a function object with the correct completion signature.
657 * The function signature of the completion handler must be:
658 * @code void handler(
659 * const boost::system::error_code& error, // Result of operation.
660 * std::size_t bytes_transferred // Number of bytes sent.
661 * ); @endcode
662 * Regardless of whether the asynchronous operation completes immediately or
663 * not, the completion handler will not be invoked from within this function.
664 * On immediate completion, invocation of the handler will be performed in a
665 * manner equivalent to using boost::asio::post().
666 *
667 * @par Completion Signature
668 * @code void(boost::system::error_code, std::size_t) @endcode
669 *
670 * @par Example
671 * To send a single data buffer use the @ref buffer function as follows:
672 * @code
673 * boost::asio::ip::udp::endpoint destination(
674 * boost::asio::ip::address::from_string("1.2.3.4"), 12345);
675 * socket.async_send_to(
676 * boost::asio::buffer(data, size), destination, handler);
677 * @endcode
678 * See the @ref buffer documentation for information on sending multiple
679 * buffers in one go, and how to use it with arrays, boost::array or
680 * std::vector.
681 *
682 * @par Per-Operation Cancellation
683 * On POSIX or Windows operating systems, this asynchronous operation supports
684 * cancellation for the following boost::asio::cancellation_type values:
685 *
686 * @li @c cancellation_type::terminal
687 *
688 * @li @c cancellation_type::partial
689 *
690 * @li @c cancellation_type::total
691 */
692 template <typename ConstBufferSequence,
693 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
694 std::size_t)) WriteToken
695 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
696 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
697 void (boost::system::error_code, std::size_t))
698 async_send_to(const ConstBufferSequence& buffers,
699 const endpoint_type& destination,
700 BOOST_ASIO_MOVE_ARG(WriteToken) token
701 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
702 {
703 return async_initiate<WriteToken,
704 void (boost::system::error_code, std::size_t)>(
705 initiate_async_send_to(this), token, buffers,
706 destination, socket_base::message_flags(0));
707 }
708
709 /// Start an asynchronous send.
710 /**
711 * This function is used to asynchronously send a datagram to the specified
712 * remote endpoint. It is an initiating function for an @ref
713 * asynchronous_operation, and always returns immediately.
714 *
715 * @param buffers One or more data buffers to be sent to the remote endpoint.
716 * Although the buffers object may be copied as necessary, ownership of the
717 * underlying memory blocks is retained by the caller, which must guarantee
718 * that they remain valid until the completion handler is called.
719 *
720 * @param flags Flags specifying how the send call is to be made.
721 *
722 * @param destination The remote endpoint to which the data will be sent.
723 * Copies will be made of the endpoint as required.
724 *
725 * @param token The @ref completion_token that will be used to produce a
726 * completion handler, which will be called when the send completes. Potential
727 * completion tokens include @ref use_future, @ref use_awaitable, @ref
728 * yield_context, or a function object with the correct completion signature.
729 * The function signature of the completion handler must be:
730 * @code void handler(
731 * const boost::system::error_code& error, // Result of operation.
732 * std::size_t bytes_transferred // Number of bytes sent.
733 * ); @endcode
734 * Regardless of whether the asynchronous operation completes immediately or
735 * not, the completion handler will not be invoked from within this function.
736 * On immediate completion, invocation of the handler will be performed in a
737 * manner equivalent to using boost::asio::post().
738 *
739 * @par Completion Signature
740 * @code void(boost::system::error_code, std::size_t) @endcode
741 *
742 * @par Per-Operation Cancellation
743 * On POSIX or Windows operating systems, this asynchronous operation supports
744 * cancellation for the following boost::asio::cancellation_type values:
745 *
746 * @li @c cancellation_type::terminal
747 *
748 * @li @c cancellation_type::partial
749 *
750 * @li @c cancellation_type::total
751 */
752 template <typename ConstBufferSequence,
753 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
754 std::size_t)) WriteToken
755 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
756 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
757 void (boost::system::error_code, std::size_t))
758 async_send_to(const ConstBufferSequence& buffers,
759 const endpoint_type& destination, socket_base::message_flags flags,
760 BOOST_ASIO_MOVE_ARG(WriteToken) token
761 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
762 {
763 return async_initiate<WriteToken,
764 void (boost::system::error_code, std::size_t)>(
765 initiate_async_send_to(this), token, buffers, destination, flags);
766 }
767
768 /// Receive some data on a connected socket.
769 /**
770 * This function is used to receive data on the datagram socket. The function
771 * call will block until data has been received successfully or an error
772 * occurs.
773 *
774 * @param buffers One or more buffers into which the data will be received.
775 *
776 * @returns The number of bytes received.
777 *
778 * @throws boost::system::system_error Thrown on failure.
779 *
780 * @note The receive operation can only be used with a connected socket. Use
781 * the receive_from function to receive data on an unconnected datagram
782 * socket.
783 *
784 * @par Example
785 * To receive into a single data buffer use the @ref buffer function as
786 * follows:
787 * @code socket.receive(boost::asio::buffer(data, size)); @endcode
788 * See the @ref buffer documentation for information on receiving into
789 * multiple buffers in one go, and how to use it with arrays, boost::array or
790 * std::vector.
791 */
792 template <typename MutableBufferSequence>
793 std::size_t receive(const MutableBufferSequence& buffers)
794 {
795 boost::system::error_code ec;
796 std::size_t s = this->impl_.get_service().receive(
797 this->impl_.get_implementation(), buffers, 0, ec);
798 boost::asio::detail::throw_error(ec, "receive");
799 return s;
800 }
801
802 /// Receive some data on a connected socket.
803 /**
804 * This function is used to receive data on the datagram socket. The function
805 * call will block until data has been received successfully or an error
806 * occurs.
807 *
808 * @param buffers One or more buffers into which the data will be received.
809 *
810 * @param flags Flags specifying how the receive call is to be made.
811 *
812 * @returns The number of bytes received.
813 *
814 * @throws boost::system::system_error Thrown on failure.
815 *
816 * @note The receive operation can only be used with a connected socket. Use
817 * the receive_from function to receive data on an unconnected datagram
818 * socket.
819 */
820 template <typename MutableBufferSequence>
821 std::size_t receive(const MutableBufferSequence& buffers,
822 socket_base::message_flags flags)
823 {
824 boost::system::error_code ec;
825 std::size_t s = this->impl_.get_service().receive(
826 this->impl_.get_implementation(), buffers, flags, ec);
827 boost::asio::detail::throw_error(ec, "receive");
828 return s;
829 }
830
831 /// Receive some data on a connected socket.
832 /**
833 * This function is used to receive data on the datagram socket. The function
834 * call will block until data has been received successfully or an error
835 * occurs.
836 *
837 * @param buffers One or more buffers into which the data will be received.
838 *
839 * @param flags Flags specifying how the receive call is to be made.
840 *
841 * @param ec Set to indicate what error occurred, if any.
842 *
843 * @returns The number of bytes received.
844 *
845 * @note The receive operation can only be used with a connected socket. Use
846 * the receive_from function to receive data on an unconnected datagram
847 * socket.
848 */
849 template <typename MutableBufferSequence>
850 std::size_t receive(const MutableBufferSequence& buffers,
851 socket_base::message_flags flags, boost::system::error_code& ec)
852 {
853 return this->impl_.get_service().receive(
854 this->impl_.get_implementation(), buffers, flags, ec);
855 }
856
857 /// Start an asynchronous receive on a connected socket.
858 /**
859 * This function is used to asynchronously receive data from the datagram
860 * socket. It is an initiating function for an @ref asynchronous_operation,
861 * and always returns immediately.
862 *
863 * @param buffers One or more buffers into which the data will be received.
864 * Although the buffers object may be copied as necessary, ownership of the
865 * underlying memory blocks is retained by the caller, which must guarantee
866 * that they remain valid until the completion handler is called.
867 *
868 * @param token The @ref completion_token that will be used to produce a
869 * completion handler, which will be called when the receive completes.
870 * Potential completion tokens include @ref use_future, @ref use_awaitable,
871 * @ref yield_context, or a function object with the correct completion
872 * signature. The function signature of the completion handler must be:
873 * @code void handler(
874 * const boost::system::error_code& error, // Result of operation.
875 * std::size_t bytes_transferred // Number of bytes received.
876 * ); @endcode
877 * Regardless of whether the asynchronous operation completes immediately or
878 * not, the completion handler will not be invoked from within this function.
879 * On immediate completion, invocation of the handler will be performed in a
880 * manner equivalent to using boost::asio::post().
881 *
882 * @par Completion Signature
883 * @code void(boost::system::error_code, std::size_t) @endcode
884 *
885 * @note The async_receive operation can only be used with a connected socket.
886 * Use the async_receive_from function to receive data on an unconnected
887 * datagram socket.
888 *
889 * @par Example
890 * To receive into a single data buffer use the @ref buffer function as
891 * follows:
892 * @code
893 * socket.async_receive(boost::asio::buffer(data, size), handler);
894 * @endcode
895 * See the @ref buffer documentation for information on receiving into
896 * multiple buffers in one go, and how to use it with arrays, boost::array or
897 * std::vector.
898 *
899 * @par Per-Operation Cancellation
900 * On POSIX or Windows operating systems, this asynchronous operation supports
901 * cancellation for the following boost::asio::cancellation_type values:
902 *
903 * @li @c cancellation_type::terminal
904 *
905 * @li @c cancellation_type::partial
906 *
907 * @li @c cancellation_type::total
908 */
909 template <typename MutableBufferSequence,
910 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
911 std::size_t)) ReadToken
912 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
913 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadToken,
914 void (boost::system::error_code, std::size_t))
915 async_receive(const MutableBufferSequence& buffers,
916 BOOST_ASIO_MOVE_ARG(ReadToken) token
917 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
918 {
919 return async_initiate<ReadToken,
920 void (boost::system::error_code, std::size_t)>(
921 initiate_async_receive(this), token,
922 buffers, socket_base::message_flags(0));
923 }
924
925 /// Start an asynchronous receive on a connected socket.
926 /**
927 * This function is used to asynchronously receive data from the datagram
928 * socket. It is an initiating function for an @ref asynchronous_operation,
929 * and always returns immediately.
930 *
931 * @param buffers One or more buffers into which the data will be received.
932 * Although the buffers object may be copied as necessary, ownership of the
933 * underlying memory blocks is retained by the caller, which must guarantee
934 * that they remain valid until the completion handler is called.
935 *
936 * @param flags Flags specifying how the receive call is to be made.
937 *
938 * @param token The @ref completion_token that will be used to produce a
939 * completion handler, which will be called when the receive completes.
940 * Potential completion tokens include @ref use_future, @ref use_awaitable,
941 * @ref yield_context, or a function object with the correct completion
942 * signature. The function signature of the completion handler must be:
943 * @code void handler(
944 * const boost::system::error_code& error, // Result of operation.
945 * std::size_t bytes_transferred // Number of bytes received.
946 * ); @endcode
947 * Regardless of whether the asynchronous operation completes immediately or
948 * not, the completion handler will not be invoked from within this function.
949 * On immediate completion, invocation of the handler will be performed in a
950 * manner equivalent to using boost::asio::post().
951 *
952 * @par Completion Signature
953 * @code void(boost::system::error_code, std::size_t) @endcode
954 *
955 * @note The async_receive operation can only be used with a connected socket.
956 * Use the async_receive_from function to receive data on an unconnected
957 * datagram socket.
958 *
959 * @par Per-Operation Cancellation
960 * On POSIX or Windows operating systems, this asynchronous operation supports
961 * cancellation for the following boost::asio::cancellation_type values:
962 *
963 * @li @c cancellation_type::terminal
964 *
965 * @li @c cancellation_type::partial
966 *
967 * @li @c cancellation_type::total
968 */
969 template <typename MutableBufferSequence,
970 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
971 std::size_t)) ReadToken
972 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
973 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadToken,
974 void (boost::system::error_code, std::size_t))
975 async_receive(const MutableBufferSequence& buffers,
976 socket_base::message_flags flags,
977 BOOST_ASIO_MOVE_ARG(ReadToken) token
978 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
979 {
980 return async_initiate<ReadToken,
981 void (boost::system::error_code, std::size_t)>(
982 initiate_async_receive(this), token, buffers, flags);
983 }
984
985 /// Receive a datagram with the endpoint of the sender.
986 /**
987 * This function is used to receive a datagram. The function call will block
988 * until data has been received successfully or an error occurs.
989 *
990 * @param buffers One or more buffers into which the data will be received.
991 *
992 * @param sender_endpoint An endpoint object that receives the endpoint of
993 * the remote sender of the datagram.
994 *
995 * @returns The number of bytes received.
996 *
997 * @throws boost::system::system_error Thrown on failure.
998 *
999 * @par Example
1000 * To receive into a single data buffer use the @ref buffer function as
1001 * follows:
1002 * @code
1003 * boost::asio::ip::udp::endpoint sender_endpoint;
1004 * socket.receive_from(
1005 * boost::asio::buffer(data, size), sender_endpoint);
1006 * @endcode
1007 * See the @ref buffer documentation for information on receiving into
1008 * multiple buffers in one go, and how to use it with arrays, boost::array or
1009 * std::vector.
1010 */
1011 template <typename MutableBufferSequence>
1012 std::size_t receive_from(const MutableBufferSequence& buffers,
1013 endpoint_type& sender_endpoint)
1014 {
1015 boost::system::error_code ec;
1016 std::size_t s = this->impl_.get_service().receive_from(
1017 this->impl_.get_implementation(), buffers, sender_endpoint, 0, ec);
1018 boost::asio::detail::throw_error(ec, "receive_from");
1019 return s;
1020 }
1021
1022 /// Receive a datagram with the endpoint of the sender.
1023 /**
1024 * This function is used to receive a datagram. The function call will block
1025 * until data has been received successfully or an error occurs.
1026 *
1027 * @param buffers One or more buffers into which the data will be received.
1028 *
1029 * @param sender_endpoint An endpoint object that receives the endpoint of
1030 * the remote sender of the datagram.
1031 *
1032 * @param flags Flags specifying how the receive call is to be made.
1033 *
1034 * @returns The number of bytes received.
1035 *
1036 * @throws boost::system::system_error Thrown on failure.
1037 */
1038 template <typename MutableBufferSequence>
1039 std::size_t receive_from(const MutableBufferSequence& buffers,
1040 endpoint_type& sender_endpoint, socket_base::message_flags flags)
1041 {
1042 boost::system::error_code ec;
1043 std::size_t s = this->impl_.get_service().receive_from(
1044 this->impl_.get_implementation(), buffers, sender_endpoint, flags, ec);
1045 boost::asio::detail::throw_error(ec, "receive_from");
1046 return s;
1047 }
1048
1049 /// Receive a datagram with the endpoint of the sender.
1050 /**
1051 * This function is used to receive a datagram. The function call will block
1052 * until data has been received successfully or an error occurs.
1053 *
1054 * @param buffers One or more buffers into which the data will be received.
1055 *
1056 * @param sender_endpoint An endpoint object that receives the endpoint of
1057 * the remote sender of the datagram.
1058 *
1059 * @param flags Flags specifying how the receive call is to be made.
1060 *
1061 * @param ec Set to indicate what error occurred, if any.
1062 *
1063 * @returns The number of bytes received.
1064 */
1065 template <typename MutableBufferSequence>
1066 std::size_t receive_from(const MutableBufferSequence& buffers,
1067 endpoint_type& sender_endpoint, socket_base::message_flags flags,
1068 boost::system::error_code& ec)
1069 {
1070 return this->impl_.get_service().receive_from(
1071 this->impl_.get_implementation(), buffers, sender_endpoint, flags, ec);
1072 }
1073
1074 /// Start an asynchronous receive.
1075 /**
1076 * This function is used to asynchronously receive a datagram. It is an
1077 * initiating function for an @ref asynchronous_operation, and always returns
1078 * immediately.
1079 *
1080 * @param buffers One or more buffers into which the data will be received.
1081 * Although the buffers object may be copied as necessary, ownership of the
1082 * underlying memory blocks is retained by the caller, which must guarantee
1083 * that they remain valid until the completion handler is called.
1084 *
1085 * @param sender_endpoint An endpoint object that receives the endpoint of
1086 * the remote sender of the datagram. Ownership of the sender_endpoint object
1087 * is retained by the caller, which must guarantee that it is valid until the
1088 * completion handler is called.
1089 *
1090 * @param token The @ref completion_token that will be used to produce a
1091 * completion handler, which will be called when the receive completes.
1092 * Potential completion tokens include @ref use_future, @ref use_awaitable,
1093 * @ref yield_context, or a function object with the correct completion
1094 * signature. The function signature of the completion handler must be:
1095 * @code void handler(
1096 * const boost::system::error_code& error, // Result of operation.
1097 * std::size_t bytes_transferred // Number of bytes received.
1098 * ); @endcode
1099 * Regardless of whether the asynchronous operation completes immediately or
1100 * not, the completion handler will not be invoked from within this function.
1101 * On immediate completion, invocation of the handler will be performed in a
1102 * manner equivalent to using boost::asio::post().
1103 *
1104 * @par Completion Signature
1105 * @code void(boost::system::error_code, std::size_t) @endcode
1106 *
1107 * @par Example
1108 * To receive into a single data buffer use the @ref buffer function as
1109 * follows:
1110 * @code socket.async_receive_from(
1111 * boost::asio::buffer(data, size), sender_endpoint, handler); @endcode
1112 * See the @ref buffer documentation for information on receiving into
1113 * multiple buffers in one go, and how to use it with arrays, boost::array or
1114 * std::vector.
1115 *
1116 * @par Per-Operation Cancellation
1117 * On POSIX or Windows operating systems, this asynchronous operation supports
1118 * cancellation for the following boost::asio::cancellation_type values:
1119 *
1120 * @li @c cancellation_type::terminal
1121 *
1122 * @li @c cancellation_type::partial
1123 *
1124 * @li @c cancellation_type::total
1125 */
1126 template <typename MutableBufferSequence,
1127 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
1128 std::size_t)) ReadToken
1129 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
1130 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadToken,
1131 void (boost::system::error_code, std::size_t))
1132 async_receive_from(const MutableBufferSequence& buffers,
1133 endpoint_type& sender_endpoint,
1134 BOOST_ASIO_MOVE_ARG(ReadToken) token
1135 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
1136 {
1137 return async_initiate<ReadToken,
1138 void (boost::system::error_code, std::size_t)>(
1139 initiate_async_receive_from(this), token, buffers,
1140 &sender_endpoint, socket_base::message_flags(0));
1141 }
1142
1143 /// Start an asynchronous receive.
1144 /**
1145 * This function is used to asynchronously receive a datagram. It is an
1146 * initiating function for an @ref asynchronous_operation, and always returns
1147 * immediately.
1148 *
1149 * @param buffers One or more buffers into which the data will be received.
1150 * Although the buffers object may be copied as necessary, ownership of the
1151 * underlying memory blocks is retained by the caller, which must guarantee
1152 * that they remain valid until the completion handler is called.
1153 *
1154 * @param sender_endpoint An endpoint object that receives the endpoint of
1155 * the remote sender of the datagram. Ownership of the sender_endpoint object
1156 * is retained by the caller, which must guarantee that it is valid until the
1157 * completion handler is called.
1158 *
1159 * @param flags Flags specifying how the receive call is to be made.
1160 *
1161 * @param token The @ref completion_token that will be used to produce a
1162 * completion handler, which will be called when the receive completes.
1163 * Potential completion tokens include @ref use_future, @ref use_awaitable,
1164 * @ref yield_context, or a function object with the correct completion
1165 * signature. The function signature of the completion handler must be:
1166 * @code void handler(
1167 * const boost::system::error_code& error, // Result of operation.
1168 * std::size_t bytes_transferred // Number of bytes received.
1169 * ); @endcode
1170 * Regardless of whether the asynchronous operation completes immediately or
1171 * not, the completion handler will not be invoked from within this function.
1172 * On immediate completion, invocation of the handler will be performed in a
1173 * manner equivalent to using boost::asio::post().
1174 *
1175 * @par Completion Signature
1176 * @code void(boost::system::error_code, std::size_t) @endcode
1177 *
1178 * @par Per-Operation Cancellation
1179 * On POSIX or Windows operating systems, this asynchronous operation supports
1180 * cancellation for the following boost::asio::cancellation_type values:
1181 *
1182 * @li @c cancellation_type::terminal
1183 *
1184 * @li @c cancellation_type::partial
1185 *
1186 * @li @c cancellation_type::total
1187 */
1188 template <typename MutableBufferSequence,
1189 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
1190 std::size_t)) ReadToken
1191 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
1192 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadToken,
1193 void (boost::system::error_code, std::size_t))
1194 async_receive_from(const MutableBufferSequence& buffers,
1195 endpoint_type& sender_endpoint, socket_base::message_flags flags,
1196 BOOST_ASIO_MOVE_ARG(ReadToken) token
1197 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
1198 {
1199 return async_initiate<ReadToken,
1200 void (boost::system::error_code, std::size_t)>(
1201 initiate_async_receive_from(this), token,
1202 buffers, &sender_endpoint, flags);
1203 }
1204
1205 private:
1206 // Disallow copying and assignment.
1207 basic_datagram_socket(const basic_datagram_socket&) BOOST_ASIO_DELETED;
1208 basic_datagram_socket& operator=(
1209 const basic_datagram_socket&) BOOST_ASIO_DELETED;
1210
1211 class initiate_async_send
1212 {
1213 public:
1214 typedef Executor executor_type;
1215
1216 explicit initiate_async_send(basic_datagram_socket* self)
1217 : self_(self)
1218 {
1219 }
1220
1221 executor_type get_executor() const BOOST_ASIO_NOEXCEPT
1222 {
1223 return self_->get_executor();
1224 }
1225
1226 template <typename WriteHandler, typename ConstBufferSequence>
1227 void operator()(BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
1228 const ConstBufferSequence& buffers,
1229 socket_base::message_flags flags) const
1230 {
1231 // If you get an error on the following line it means that your handler
1232 // does not meet the documented type requirements for a WriteHandler.
1233 BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
1234
1235 detail::non_const_lvalue<WriteHandler> handler2(handler);
1236 self_->impl_.get_service().async_send(
1237 self_->impl_.get_implementation(), buffers, flags,
1238 handler2.value, self_->impl_.get_executor());
1239 }
1240
1241 private:
1242 basic_datagram_socket* self_;
1243 };
1244
1245 class initiate_async_send_to
1246 {
1247 public:
1248 typedef Executor executor_type;
1249
1250 explicit initiate_async_send_to(basic_datagram_socket* self)
1251 : self_(self)
1252 {
1253 }
1254
1255 executor_type get_executor() const BOOST_ASIO_NOEXCEPT
1256 {
1257 return self_->get_executor();
1258 }
1259
1260 template <typename WriteHandler, typename ConstBufferSequence>
1261 void operator()(BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
1262 const ConstBufferSequence& buffers, const endpoint_type& destination,
1263 socket_base::message_flags flags) const
1264 {
1265 // If you get an error on the following line it means that your handler
1266 // does not meet the documented type requirements for a WriteHandler.
1267 BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
1268
1269 detail::non_const_lvalue<WriteHandler> handler2(handler);
1270 self_->impl_.get_service().async_send_to(
1271 self_->impl_.get_implementation(), buffers, destination,
1272 flags, handler2.value, self_->impl_.get_executor());
1273 }
1274
1275 private:
1276 basic_datagram_socket* self_;
1277 };
1278
1279 class initiate_async_receive
1280 {
1281 public:
1282 typedef Executor executor_type;
1283
1284 explicit initiate_async_receive(basic_datagram_socket* self)
1285 : self_(self)
1286 {
1287 }
1288
1289 executor_type get_executor() const BOOST_ASIO_NOEXCEPT
1290 {
1291 return self_->get_executor();
1292 }
1293
1294 template <typename ReadHandler, typename MutableBufferSequence>
1295 void operator()(BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
1296 const MutableBufferSequence& buffers,
1297 socket_base::message_flags flags) const
1298 {
1299 // If you get an error on the following line it means that your handler
1300 // does not meet the documented type requirements for a ReadHandler.
1301 BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
1302
1303 detail::non_const_lvalue<ReadHandler> handler2(handler);
1304 self_->impl_.get_service().async_receive(
1305 self_->impl_.get_implementation(), buffers, flags,
1306 handler2.value, self_->impl_.get_executor());
1307 }
1308
1309 private:
1310 basic_datagram_socket* self_;
1311 };
1312
1313 class initiate_async_receive_from
1314 {
1315 public:
1316 typedef Executor executor_type;
1317
1318 explicit initiate_async_receive_from(basic_datagram_socket* self)
1319 : self_(self)
1320 {
1321 }
1322
1323 executor_type get_executor() const BOOST_ASIO_NOEXCEPT
1324 {
1325 return self_->get_executor();
1326 }
1327
1328 template <typename ReadHandler, typename MutableBufferSequence>
1329 void operator()(BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
1330 const MutableBufferSequence& buffers, endpoint_type* sender_endpoint,
1331 socket_base::message_flags flags) const
1332 {
1333 // If you get an error on the following line it means that your handler
1334 // does not meet the documented type requirements for a ReadHandler.
1335 BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
1336
1337 detail::non_const_lvalue<ReadHandler> handler2(handler);
1338 self_->impl_.get_service().async_receive_from(
1339 self_->impl_.get_implementation(), buffers, *sender_endpoint,
1340 flags, handler2.value, self_->impl_.get_executor());
1341 }
1342
1343 private:
1344 basic_datagram_socket* self_;
1345 };
1346 };
1347
1348 } // namespace asio
1349 } // namespace boost
1350
1351 #include <boost/asio/detail/pop_options.hpp>
1352
1353 #endif // BOOST_ASIO_BASIC_DATAGRAM_SOCKET_HPP