11 #ifndef ASIO_BASIC_DATAGRAM_SOCKET_HPP 12 #define ASIO_BASIC_DATAGRAM_SOCKET_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 18 #include "asio/detail/config.hpp" 20 #include "asio/basic_socket.hpp" 21 #include "asio/detail/handler_type_requirements.hpp" 22 #include "asio/detail/non_const_lvalue.hpp" 23 #include "asio/detail/throw_error.hpp" 24 #include "asio/detail/type_traits.hpp" 25 #include "asio/error.hpp" 27 #include "asio/detail/push_options.hpp" 31 #if !defined(ASIO_BASIC_DATAGRAM_SOCKET_FWD_DECL) 32 #define ASIO_BASIC_DATAGRAM_SOCKET_FWD_DECL 35 template <
typename Protocol,
typename Executor = any_io_executor>
38 #endif // !defined(ASIO_BASIC_DATAGRAM_SOCKET_FWD_DECL) 49 template <
typename Protocol,
typename Executor>
58 template <
typename Executor1>
66 #if defined(GENERATING_DOCUMENTATION) 101 template <
typename ExecutionContext>
104 is_convertible<ExecutionContext&, execution_context&>::value
138 template <
typename ExecutionContext>
140 const protocol_type& protocol,
142 is_convertible<ExecutionContext&, execution_context&>::value
184 template <
typename ExecutionContext>
186 const endpoint_type& endpoint,
188 is_convertible<ExecutionContext&, execution_context&>::value
209 const protocol_type& protocol,
const native_handle_type& native_socket)
210 :
basic_socket<Protocol, Executor>(ex, protocol, native_socket)
229 template <
typename ExecutionContext>
231 const protocol_type& protocol,
const native_handle_type& native_socket,
233 is_convertible<ExecutionContext&, execution_context&>::value
235 :
basic_socket<Protocol, Executor>(context, protocol, native_socket)
239 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 286 template <
typename Protocol1,
typename Executor1>
289 is_convertible<Protocol1, Protocol>::value
290 && is_convertible<Executor1, Executor>::value
309 template <
typename Protocol1,
typename Executor1>
311 is_convertible<Protocol1, Protocol>::value
312 && is_convertible<Executor1, Executor>::value,
319 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 352 template <
typename ConstBufferSequence>
353 std::size_t
send(
const ConstBufferSequence& buffers)
356 std::size_t
s = this->impl_.get_service().send(
357 this->impl_.get_implementation(), buffers, 0, ec);
358 asio::detail::throw_error(ec,
"send");
379 template <
typename ConstBufferSequence>
380 std::size_t
send(
const ConstBufferSequence& buffers,
384 std::size_t
s = this->impl_.get_service().send(
385 this->impl_.get_implementation(), buffers, flags, ec);
386 asio::detail::throw_error(ec,
"send");
407 template <
typename ConstBufferSequence>
408 std::size_t
send(
const ConstBufferSequence& buffers,
411 return this->impl_.get_service().send(
412 this->impl_.get_implementation(), buffers, flags, ec);
450 template <
typename ConstBufferSequence,
452 std::size_t)) WriteHandler
453 ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
456 async_send(
const ConstBufferSequence& buffers,
457 ASIO_MOVE_ARG(WriteHandler) handler
458 ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
460 return async_initiate<WriteHandler,
462 initiate_async_send(
this), handler,
494 template <
typename ConstBufferSequence,
496 std::size_t)) WriteHandler
497 ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
500 async_send(
const ConstBufferSequence& buffers,
502 ASIO_MOVE_ARG(WriteHandler) handler
503 ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
505 return async_initiate<WriteHandler,
507 initiate_async_send(
this), handler, buffers, flags);
535 template <
typename ConstBufferSequence>
536 std::size_t
send_to(
const ConstBufferSequence& buffers,
537 const endpoint_type& destination)
540 std::size_t
s = this->impl_.get_service().send_to(
541 this->impl_.get_implementation(), buffers, destination, 0, ec);
542 asio::detail::throw_error(ec,
"send_to");
562 template <
typename ConstBufferSequence>
563 std::size_t
send_to(
const ConstBufferSequence& buffers,
567 std::size_t
s = this->impl_.get_service().send_to(
568 this->impl_.get_implementation(), buffers, destination, flags, ec);
569 asio::detail::throw_error(ec,
"send_to");
589 template <
typename ConstBufferSequence>
590 std::size_t
send_to(
const ConstBufferSequence& buffers,
594 return this->impl_.get_service().send_to(this->impl_.get_implementation(),
595 buffers, destination, flags, ec);
635 template <
typename ConstBufferSequence,
637 std::size_t)) WriteHandler
638 ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
641 async_send_to(
const ConstBufferSequence& buffers,
642 const endpoint_type& destination,
643 ASIO_MOVE_ARG(WriteHandler) handler
644 ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
646 return async_initiate<WriteHandler,
648 initiate_async_send_to(
this), handler, buffers,
679 template <
typename ConstBufferSequence,
681 std::size_t)) WriteHandler
682 ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
685 async_send_to(
const ConstBufferSequence& buffers,
687 ASIO_MOVE_ARG(WriteHandler) handler
688 ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
690 return async_initiate<WriteHandler,
692 initiate_async_send_to(
this), handler, buffers, destination, flags);
719 template <
typename MutableBufferSequence>
720 std::size_t
receive(
const MutableBufferSequence& buffers)
723 std::size_t
s = this->impl_.get_service().receive(
724 this->impl_.get_implementation(), buffers, 0, ec);
725 asio::detail::throw_error(ec,
"receive");
747 template <
typename MutableBufferSequence>
748 std::size_t
receive(
const MutableBufferSequence& buffers,
752 std::size_t
s = this->impl_.get_service().receive(
753 this->impl_.get_implementation(), buffers, flags, ec);
754 asio::detail::throw_error(ec,
"receive");
776 template <
typename MutableBufferSequence>
777 std::size_t
receive(
const MutableBufferSequence& buffers,
780 return this->impl_.get_service().receive(
781 this->impl_.get_implementation(), buffers, flags, ec);
820 template <
typename MutableBufferSequence,
822 std::size_t)) ReadHandler
823 ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
826 async_receive(
const MutableBufferSequence& buffers,
827 ASIO_MOVE_ARG(ReadHandler) handler
828 ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
830 return async_initiate<ReadHandler,
832 initiate_async_receive(
this), handler,
864 template <
typename MutableBufferSequence,
866 std::size_t)) ReadHandler
867 ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
870 async_receive(
const MutableBufferSequence& buffers,
872 ASIO_MOVE_ARG(ReadHandler) handler
873 ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
875 return async_initiate<ReadHandler,
877 initiate_async_receive(
this), handler, buffers, flags);
906 template <
typename MutableBufferSequence>
908 endpoint_type& sender_endpoint)
911 std::size_t
s = this->impl_.get_service().receive_from(
912 this->impl_.get_implementation(), buffers, sender_endpoint, 0, ec);
913 asio::detail::throw_error(ec,
"receive_from");
933 template <
typename MutableBufferSequence>
938 std::size_t
s = this->impl_.get_service().receive_from(
939 this->impl_.get_implementation(), buffers, sender_endpoint, flags, ec);
940 asio::detail::throw_error(ec,
"receive_from");
960 template <
typename MutableBufferSequence>
965 return this->impl_.get_service().receive_from(
966 this->impl_.get_implementation(), buffers, sender_endpoint, flags, ec);
1005 template <
typename MutableBufferSequence,
1007 std::size_t)) ReadHandler
1008 ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
1011 async_receive_from(
const MutableBufferSequence& buffers,
1012 endpoint_type& sender_endpoint,
1013 ASIO_MOVE_ARG(ReadHandler) handler
1014 ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
1016 return async_initiate<ReadHandler,
1018 initiate_async_receive_from(
this), handler, buffers,
1051 template <
typename MutableBufferSequence,
1053 std::size_t)) ReadHandler
1054 ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
1057 async_receive_from(
const MutableBufferSequence& buffers,
1059 ASIO_MOVE_ARG(ReadHandler) handler
1060 ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
1062 return async_initiate<ReadHandler,
1064 initiate_async_receive_from(
this), handler,
1065 buffers, &sender_endpoint, flags);
1074 class initiate_async_send
1086 return self_->get_executor();
1089 template <
typename WriteHandler,
typename ConstBufferSequence>
1090 void operator()(ASIO_MOVE_ARG(WriteHandler) handler,
1091 const ConstBufferSequence& buffers,
1096 ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
1099 self_->impl_.get_service().async_send(
1100 self_->impl_.get_implementation(), buffers, flags,
1101 handler2.value, self_->impl_.get_executor());
1108 class initiate_async_send_to
1120 return self_->get_executor();
1123 template <
typename WriteHandler,
typename ConstBufferSequence>
1124 void operator()(ASIO_MOVE_ARG(WriteHandler) handler,
1125 const ConstBufferSequence& buffers,
const endpoint_type& destination,
1130 ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
1133 self_->impl_.get_service().async_send_to(
1134 self_->impl_.get_implementation(), buffers, destination,
1135 flags, handler2.value, self_->impl_.get_executor());
1142 class initiate_async_receive
1154 return self_->get_executor();
1157 template <
typename ReadHandler,
typename MutableBufferSequence>
1158 void operator()(ASIO_MOVE_ARG(ReadHandler) handler,
1159 const MutableBufferSequence& buffers,
1164 ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
1167 self_->impl_.get_service().async_receive(
1168 self_->impl_.get_implementation(), buffers, flags,
1169 handler2.value, self_->impl_.get_executor());
1176 class initiate_async_receive_from
1188 return self_->get_executor();
1191 template <
typename ReadHandler,
typename MutableBufferSequence>
1192 void operator()(ASIO_MOVE_ARG(ReadHandler) handler,
1193 const MutableBufferSequence& buffers, endpoint_type* sender_endpoint,
1198 ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
1201 self_->impl_.get_service().async_receive_from(
1202 self_->impl_.get_implementation(), buffers, *sender_endpoint,
1203 flags, handler2.value, self_->impl_.get_executor());
1213 #include "asio/detail/pop_options.hpp" 1215 #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
basic_datagram_socket(ExecutionContext &context, const endpoint_type &endpoint, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
Construct a basic_datagram_socket, opening it and binding it to the given local endpoint.
Definition: basic_datagram_socket.hpp:185
Definition: blocking.hpp:208
executor_type get_executor() ASIO_NOEXCEPT
Get the executor associated with the object.
Definition: basic_socket.hpp:366
std::size_t receive(const MutableBufferSequence &buffers)
Receive some data on a connected socket.
Definition: basic_datagram_socket.hpp:720
std::size_t send(const ConstBufferSequence &buffers, socket_base::message_flags flags)
Send some data on a connected socket.
Definition: basic_datagram_socket.hpp:380
std::size_t send(const ConstBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec)
Send some data on a connected socket.
Definition: basic_datagram_socket.hpp:408
basic_datagram_socket(ExecutionContext &context, const protocol_type &protocol, const native_handle_type &native_socket, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
Construct a basic_datagram_socket on an existing native socket.
Definition: basic_datagram_socket.hpp:230
basic_datagram_socket(const executor_type &ex)
Construct a basic_datagram_socket without opening it.
Definition: basic_datagram_socket.hpp:87
basic_datagram_socket(const executor_type &ex, const protocol_type &protocol, const native_handle_type &native_socket)
Construct a basic_datagram_socket on an existing native socket.
Definition: basic_datagram_socket.hpp:208
std::size_t send(const ConstBufferSequence &buffers)
Send some data on a connected socket.
Definition: basic_datagram_socket.hpp:353
std::size_t receive(const MutableBufferSequence &buffers, socket_base::message_flags flags)
Receive some data on a connected socket.
Definition: basic_datagram_socket.hpp:748
Protocol::endpoint endpoint_type
The endpoint type.
Definition: basic_datagram_socket.hpp:77
basic_datagram_socket(const executor_type &ex, const protocol_type &protocol)
Construct and open a basic_datagram_socket.
Definition: basic_datagram_socket.hpp:121
Protocol protocol_type
The protocol type.
Definition: basic_datagram_socket.hpp:74
std::size_t send_to(const ConstBufferSequence &buffers, const endpoint_type &destination, socket_base::message_flags flags)
Send a datagram to the specified endpoint.
Definition: basic_datagram_socket.hpp:563
basic_datagram_socket(ExecutionContext &context, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
Construct a basic_datagram_socket without opening it.
Definition: basic_datagram_socket.hpp:102
basic_socket< Protocol, Executor >::native_handle_type native_handle_type
The native representation of a socket.
Definition: basic_datagram_socket.hpp:70
Executor executor_type
The type of the executor associated with the object.
Definition: basic_datagram_socket.hpp:55
basic_datagram_socket(const executor_type &ex, const endpoint_type &endpoint)
Construct a basic_datagram_socket, opening it and binding it to the given local endpoint.
Definition: basic_datagram_socket.hpp:163
std::size_t send_to(const ConstBufferSequence &buffers, const endpoint_type &destination)
Send a datagram to the specified endpoint.
Definition: basic_datagram_socket.hpp:536
Provides datagram-oriented socket functionality.
Definition: basic_datagram_socket.hpp:36
Definition: type_traits.hpp:97
Definition: non_const_lvalue.hpp:27
detail::reactive_socket_service< Protocol >::native_handle_type native_handle_type
The native representation of a socket.
Definition: basic_socket.hpp:92
std::size_t receive(const MutableBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec)
Receive some data on a connected socket.
Definition: basic_datagram_socket.hpp:777
Class to represent an error code value.
Definition: error_code.hpp:80
ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler, void(asio::error_code, std::size_t)) async_send(const ConstBufferSequence &buffers
Start an asynchronous send on a connected socket.
basic_datagram_socket(ExecutionContext &context, const protocol_type &protocol, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
Construct and open a basic_datagram_socket.
Definition: basic_datagram_socket.hpp:139
~basic_datagram_socket()
Destroys the socket.
Definition: basic_datagram_socket.hpp:326
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.
Definition: basic_datagram_socket.hpp:590
Provides socket functionality.
Definition: basic_socket.hpp:52
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.
Definition: basic_datagram_socket.hpp:934
basic_datagram_socket< Protocol, Executor1 > other
The socket type when rebound to the specified executor.
Definition: basic_datagram_socket.hpp:62
Definition: any_io_executor.hpp:28
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.
Definition: basic_datagram_socket.hpp:961
std::size_t receive_from(const MutableBufferSequence &buffers, endpoint_type &sender_endpoint)
Receive a datagram with the endpoint of the sender.
Definition: basic_datagram_socket.hpp:907
Rebinds the socket type to another executor.
Definition: basic_datagram_socket.hpp:59