summaryrefslogtreecommitdiff
path: root/boost/asio/basic_datagram_socket.hpp
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2019-12-05 15:11:01 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2019-12-05 15:11:01 +0900
commit3fdc3e5ee96dca5b11d1694975a65200787eab86 (patch)
tree5c1733853892b8397d67706fa453a9bd978d2102 /boost/asio/basic_datagram_socket.hpp
parent88e602c57797660ebe0f9e15dbd64c1ff16dead3 (diff)
downloadboost-3fdc3e5ee96dca5b11d1694975a65200787eab86.tar.gz
boost-3fdc3e5ee96dca5b11d1694975a65200787eab86.tar.bz2
boost-3fdc3e5ee96dca5b11d1694975a65200787eab86.zip
Imported Upstream version 1.66.0upstream/1.66.0
Diffstat (limited to 'boost/asio/basic_datagram_socket.hpp')
-rw-r--r--boost/asio/basic_datagram_socket.hpp187
1 files changed, 139 insertions, 48 deletions
diff --git a/boost/asio/basic_datagram_socket.hpp b/boost/asio/basic_datagram_socket.hpp
index 22801ee081..c2aa00bf48 100644
--- a/boost/asio/basic_datagram_socket.hpp
+++ b/boost/asio/basic_datagram_socket.hpp
@@ -18,12 +18,15 @@
#include <boost/asio/detail/config.hpp>
#include <cstddef>
#include <boost/asio/basic_socket.hpp>
-#include <boost/asio/datagram_socket_service.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/error.hpp>
+#if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+# include <boost/asio/datagram_socket_service.hpp>
+#endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+
#include <boost/asio/detail/push_options.hpp>
namespace boost {
@@ -38,18 +41,19 @@ namespace asio {
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*/
-template <typename Protocol,
- typename DatagramSocketService = datagram_socket_service<Protocol> >
+template <typename Protocol
+ BOOST_ASIO_SVC_TPARAM_DEF1(= datagram_socket_service<Protocol>)>
class basic_datagram_socket
- : public basic_socket<Protocol, DatagramSocketService>
+ : public basic_socket<Protocol BOOST_ASIO_SVC_TARG>
{
public:
- /// (Deprecated: Use native_handle_type.) The native representation of a
- /// socket.
- typedef typename DatagramSocketService::native_handle_type native_type;
-
/// The native representation of a socket.
- typedef typename DatagramSocketService::native_handle_type native_handle_type;
+#if defined(GENERATING_DOCUMENTATION)
+ typedef implementation_defined native_handle_type;
+#else
+ typedef typename basic_socket<
+ Protocol BOOST_ASIO_SVC_TARG>::native_handle_type native_handle_type;
+#endif
/// The protocol type.
typedef Protocol protocol_type;
@@ -62,12 +66,12 @@ public:
* This constructor creates a datagram socket without opening it. The open()
* function must be called before data can be sent or received on the socket.
*
- * @param io_service The io_service object that the datagram socket will use
+ * @param io_context The io_context object that the datagram socket will use
* to dispatch handlers for any asynchronous operations performed on the
* socket.
*/
- explicit basic_datagram_socket(boost::asio::io_service& io_service)
- : basic_socket<Protocol, DatagramSocketService>(io_service)
+ explicit basic_datagram_socket(boost::asio::io_context& io_context)
+ : basic_socket<Protocol BOOST_ASIO_SVC_TARG>(io_context)
{
}
@@ -75,7 +79,7 @@ public:
/**
* This constructor creates and opens a datagram socket.
*
- * @param io_service The io_service object that the datagram socket will use
+ * @param io_context The io_context object that the datagram socket will use
* to dispatch handlers for any asynchronous operations performed on the
* socket.
*
@@ -83,9 +87,9 @@ public:
*
* @throws boost::system::system_error Thrown on failure.
*/
- basic_datagram_socket(boost::asio::io_service& io_service,
+ basic_datagram_socket(boost::asio::io_context& io_context,
const protocol_type& protocol)
- : basic_socket<Protocol, DatagramSocketService>(io_service, protocol)
+ : basic_socket<Protocol BOOST_ASIO_SVC_TARG>(io_context, protocol)
{
}
@@ -96,7 +100,7 @@ public:
* to the specified endpoint on the local machine. The protocol used is the
* protocol associated with the given endpoint.
*
- * @param io_service The io_service object that the datagram socket will use
+ * @param io_context The io_context object that the datagram socket will use
* to dispatch handlers for any asynchronous operations performed on the
* socket.
*
@@ -105,9 +109,9 @@ public:
*
* @throws boost::system::system_error Thrown on failure.
*/
- basic_datagram_socket(boost::asio::io_service& io_service,
+ basic_datagram_socket(boost::asio::io_context& io_context,
const endpoint_type& endpoint)
- : basic_socket<Protocol, DatagramSocketService>(io_service, endpoint)
+ : basic_socket<Protocol BOOST_ASIO_SVC_TARG>(io_context, endpoint)
{
}
@@ -116,7 +120,7 @@ public:
* This constructor creates a datagram socket object to hold an existing
* native socket.
*
- * @param io_service The io_service object that the datagram socket will use
+ * @param io_context The io_context object that the datagram socket will use
* to dispatch handlers for any asynchronous operations performed on the
* socket.
*
@@ -126,10 +130,10 @@ public:
*
* @throws boost::system::system_error Thrown on failure.
*/
- basic_datagram_socket(boost::asio::io_service& io_service,
+ basic_datagram_socket(boost::asio::io_context& io_context,
const protocol_type& protocol, const native_handle_type& native_socket)
- : basic_socket<Protocol, DatagramSocketService>(
- io_service, protocol, native_socket)
+ : basic_socket<Protocol BOOST_ASIO_SVC_TARG>(
+ io_context, protocol, native_socket)
{
}
@@ -142,11 +146,10 @@ public:
* will occur.
*
* @note Following the move, the moved-from object is in the same state as if
- * constructed using the @c basic_datagram_socket(io_service&) constructor.
+ * constructed using the @c basic_datagram_socket(io_context&) constructor.
*/
basic_datagram_socket(basic_datagram_socket&& other)
- : basic_socket<Protocol, DatagramSocketService>(
- BOOST_ASIO_MOVE_CAST(basic_datagram_socket)(other))
+ : basic_socket<Protocol BOOST_ASIO_SVC_TARG>(std::move(other))
{
}
@@ -159,12 +162,11 @@ public:
* will occur.
*
* @note Following the move, the moved-from object is in the same state as if
- * constructed using the @c basic_datagram_socket(io_service&) constructor.
+ * constructed using the @c basic_datagram_socket(io_context&) constructor.
*/
basic_datagram_socket& operator=(basic_datagram_socket&& other)
{
- basic_socket<Protocol, DatagramSocketService>::operator=(
- BOOST_ASIO_MOVE_CAST(basic_datagram_socket)(other));
+ basic_socket<Protocol BOOST_ASIO_SVC_TARG>::operator=(std::move(other));
return *this;
}
@@ -177,15 +179,13 @@ public:
* will occur.
*
* @note Following the move, the moved-from object is in the same state as if
- * constructed using the @c basic_datagram_socket(io_service&) constructor.
+ * constructed using the @c basic_datagram_socket(io_context&) constructor.
*/
- template <typename Protocol1, typename DatagramSocketService1>
+ template <typename Protocol1 BOOST_ASIO_SVC_TPARAM1>
basic_datagram_socket(
- basic_datagram_socket<Protocol1, DatagramSocketService1>&& other,
+ basic_datagram_socket<Protocol1 BOOST_ASIO_SVC_TARG1>&& other,
typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
- : basic_socket<Protocol, DatagramSocketService>(
- BOOST_ASIO_MOVE_CAST2(basic_datagram_socket<
- Protocol1, DatagramSocketService1>)(other))
+ : basic_socket<Protocol BOOST_ASIO_SVC_TARG>(std::move(other))
{
}
@@ -199,20 +199,27 @@ public:
* will occur.
*
* @note Following the move, the moved-from object is in the same state as if
- * constructed using the @c basic_datagram_socket(io_service&) constructor.
+ * constructed using the @c basic_datagram_socket(io_context&) constructor.
*/
- template <typename Protocol1, typename DatagramSocketService1>
+ template <typename Protocol1 BOOST_ASIO_SVC_TPARAM1>
typename enable_if<is_convertible<Protocol1, Protocol>::value,
basic_datagram_socket>::type& operator=(
- basic_datagram_socket<Protocol1, DatagramSocketService1>&& other)
+ basic_datagram_socket<Protocol1 BOOST_ASIO_SVC_TARG1>&& other)
{
- basic_socket<Protocol, DatagramSocketService>::operator=(
- BOOST_ASIO_MOVE_CAST2(basic_datagram_socket<
- Protocol1, DatagramSocketService1>)(other));
+ basic_socket<Protocol BOOST_ASIO_SVC_TARG>::operator=(std::move(other));
return *this;
}
#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
+ /// Destroys the socket.
+ /**
+ * This function destroys the socket, cancelling any outstanding asynchronous
+ * operations associated with the socket as if by calling @c cancel.
+ */
+ ~basic_datagram_socket()
+ {
+ }
+
/// Send some data on a connected socket.
/**
* This function is used to send data on the datagram socket. The function
@@ -318,7 +325,7 @@ public:
* Regardless of whether the asynchronous operation completes immediately or
* not, the handler will not be invoked from within this function. Invocation
* of the handler will be performed in a manner equivalent to using
- * boost::asio::io_service::post().
+ * boost::asio::io_context::post().
*
* @note The async_send operation can only be used with a connected socket.
* Use the async_send_to function to send data on an unconnected datagram
@@ -343,8 +350,18 @@ public:
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
+#if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
return this->get_service().async_send(this->get_implementation(),
buffers, 0, BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
+#else // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+ async_completion<WriteHandler,
+ void (boost::system::error_code, std::size_t)> init(handler);
+
+ this->get_service().async_send(this->get_implementation(),
+ buffers, 0, init.completion_handler);
+
+ return init.result.get();
+#endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
}
/// Start an asynchronous send on a connected socket.
@@ -369,7 +386,7 @@ public:
* Regardless of whether the asynchronous operation completes immediately or
* not, the handler will not be invoked from within this function. Invocation
* of the handler will be performed in a manner equivalent to using
- * boost::asio::io_service::post().
+ * boost::asio::io_context::post().
*
* @note The async_send operation can only be used with a connected socket.
* Use the async_send_to function to send data on an unconnected datagram
@@ -386,8 +403,18 @@ public:
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
+#if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
return this->get_service().async_send(this->get_implementation(),
buffers, flags, BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
+#else // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+ async_completion<WriteHandler,
+ void (boost::system::error_code, std::size_t)> init(handler);
+
+ this->get_service().async_send(this->get_implementation(),
+ buffers, flags, init.completion_handler);
+
+ return init.result.get();
+#endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
}
/// Send a datagram to the specified endpoint.
@@ -501,7 +528,7 @@ public:
* Regardless of whether the asynchronous operation completes immediately or
* not, the handler will not be invoked from within this function. Invocation
* of the handler will be performed in a manner equivalent to using
- * boost::asio::io_service::post().
+ * boost::asio::io_context::post().
*
* @par Example
* To send a single data buffer use the @ref buffer function as follows:
@@ -526,9 +553,20 @@ public:
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
+#if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
return this->get_service().async_send_to(
this->get_implementation(), buffers, destination, 0,
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
+#else // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+ async_completion<WriteHandler,
+ void (boost::system::error_code, std::size_t)> init(handler);
+
+ this->get_service().async_send_to(
+ this->get_implementation(), buffers, destination, 0,
+ init.completion_handler);
+
+ return init.result.get();
+#endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
}
/// Start an asynchronous send.
@@ -556,7 +594,7 @@ public:
* Regardless of whether the asynchronous operation completes immediately or
* not, the handler will not be invoked from within this function. Invocation
* of the handler will be performed in a manner equivalent to using
- * boost::asio::io_service::post().
+ * boost::asio::io_context::post().
*/
template <typename ConstBufferSequence, typename WriteHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
@@ -569,9 +607,20 @@ public:
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
+#if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
return this->get_service().async_send_to(
this->get_implementation(), buffers, destination, flags,
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
+#else // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+ async_completion<WriteHandler,
+ void (boost::system::error_code, std::size_t)> init(handler);
+
+ this->get_service().async_send_to(
+ this->get_implementation(), buffers, destination, flags,
+ init.completion_handler);
+
+ return init.result.get();
+#endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
}
/// Receive some data on a connected socket.
@@ -683,7 +732,7 @@ public:
* Regardless of whether the asynchronous operation completes immediately or
* not, the handler will not be invoked from within this function. Invocation
* of the handler will be performed in a manner equivalent to using
- * boost::asio::io_service::post().
+ * boost::asio::io_context::post().
*
* @note The async_receive operation can only be used with a connected socket.
* Use the async_receive_from function to receive data on an unconnected
@@ -709,8 +758,18 @@ public:
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
+#if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
return this->get_service().async_receive(this->get_implementation(),
buffers, 0, BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
+#else // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+ async_completion<ReadHandler,
+ void (boost::system::error_code, std::size_t)> init(handler);
+
+ this->get_service().async_receive(this->get_implementation(),
+ buffers, 0, init.completion_handler);
+
+ return init.result.get();
+#endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
}
/// Start an asynchronous receive on a connected socket.
@@ -735,7 +794,7 @@ public:
* Regardless of whether the asynchronous operation completes immediately or
* not, the handler will not be invoked from within this function. Invocation
* of the handler will be performed in a manner equivalent to using
- * boost::asio::io_service::post().
+ * boost::asio::io_context::post().
*
* @note The async_receive operation can only be used with a connected socket.
* Use the async_receive_from function to receive data on an unconnected
@@ -752,8 +811,18 @@ public:
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
+#if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
return this->get_service().async_receive(this->get_implementation(),
buffers, flags, BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
+#else // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+ async_completion<ReadHandler,
+ void (boost::system::error_code, std::size_t)> init(handler);
+
+ this->get_service().async_receive(this->get_implementation(),
+ buffers, flags, init.completion_handler);
+
+ return init.result.get();
+#endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
}
/// Receive a datagram with the endpoint of the sender.
@@ -870,7 +939,7 @@ public:
* Regardless of whether the asynchronous operation completes immediately or
* not, the handler will not be invoked from within this function. Invocation
* of the handler will be performed in a manner equivalent to using
- * boost::asio::io_service::post().
+ * boost::asio::io_context::post().
*
* @par Example
* To receive into a single data buffer use the @ref buffer function as
@@ -892,9 +961,20 @@ public:
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
+#if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
return this->get_service().async_receive_from(
this->get_implementation(), buffers, sender_endpoint, 0,
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
+#else // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+ async_completion<ReadHandler,
+ void (boost::system::error_code, std::size_t)> init(handler);
+
+ this->get_service().async_receive_from(
+ this->get_implementation(), buffers, sender_endpoint, 0,
+ init.completion_handler);
+
+ return init.result.get();
+#endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
}
/// Start an asynchronous receive.
@@ -924,7 +1004,7 @@ public:
* Regardless of whether the asynchronous operation completes immediately or
* not, the handler will not be invoked from within this function. Invocation
* of the handler will be performed in a manner equivalent to using
- * boost::asio::io_service::post().
+ * boost::asio::io_context::post().
*/
template <typename MutableBufferSequence, typename ReadHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
@@ -937,9 +1017,20 @@ public:
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
+#if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
return this->get_service().async_receive_from(
this->get_implementation(), buffers, sender_endpoint, flags,
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
+#else // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+ async_completion<ReadHandler,
+ void (boost::system::error_code, std::size_t)> init(handler);
+
+ this->get_service().async_receive_from(
+ this->get_implementation(), buffers, sender_endpoint, flags,
+ init.completion_handler);
+
+ return init.result.get();
+#endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
}
};