summaryrefslogtreecommitdiff
path: root/boost/asio/basic_raw_socket.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/asio/basic_raw_socket.hpp')
-rw-r--r--boost/asio/basic_raw_socket.hpp186
1 files changed, 138 insertions, 48 deletions
diff --git a/boost/asio/basic_raw_socket.hpp b/boost/asio/basic_raw_socket.hpp
index 85f8f42642..09058de224 100644
--- a/boost/asio/basic_raw_socket.hpp
+++ b/boost/asio/basic_raw_socket.hpp
@@ -22,7 +22,10 @@
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/error.hpp>
-#include <boost/asio/raw_socket_service.hpp>
+
+#if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+# include <boost/asio/raw_socket_service.hpp>
+#endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
#include <boost/asio/detail/push_options.hpp>
@@ -38,18 +41,19 @@ namespace asio {
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*/
-template <typename Protocol,
- typename RawSocketService = raw_socket_service<Protocol> >
+template <typename Protocol
+ BOOST_ASIO_SVC_TPARAM_DEF1(= raw_socket_service<Protocol>)>
class basic_raw_socket
- : public basic_socket<Protocol, RawSocketService>
+ : public basic_socket<Protocol BOOST_ASIO_SVC_TARG>
{
public:
- /// (Deprecated: Use native_handle_type.) The native representation of a
- /// socket.
- typedef typename RawSocketService::native_handle_type native_type;
-
/// The native representation of a socket.
- typedef typename RawSocketService::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 raw 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 raw socket will use
+ * @param io_context The io_context object that the raw socket will use
* to dispatch handlers for any asynchronous operations performed on the
* socket.
*/
- explicit basic_raw_socket(boost::asio::io_service& io_service)
- : basic_socket<Protocol, RawSocketService>(io_service)
+ explicit basic_raw_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 raw socket.
*
- * @param io_service The io_service object that the raw socket will use
+ * @param io_context The io_context object that the raw 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_raw_socket(boost::asio::io_service& io_service,
+ basic_raw_socket(boost::asio::io_context& io_context,
const protocol_type& protocol)
- : basic_socket<Protocol, RawSocketService>(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 raw socket will use
+ * @param io_context The io_context object that the raw 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_raw_socket(boost::asio::io_service& io_service,
+ basic_raw_socket(boost::asio::io_context& io_context,
const endpoint_type& endpoint)
- : basic_socket<Protocol, RawSocketService>(io_service, endpoint)
+ : basic_socket<Protocol BOOST_ASIO_SVC_TARG>(io_context, endpoint)
{
}
@@ -116,7 +120,7 @@ public:
* This constructor creates a raw socket object to hold an existing
* native socket.
*
- * @param io_service The io_service object that the raw socket will use
+ * @param io_context The io_context object that the raw 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_raw_socket(boost::asio::io_service& io_service,
+ basic_raw_socket(boost::asio::io_context& io_context,
const protocol_type& protocol, const native_handle_type& native_socket)
- : basic_socket<Protocol, RawSocketService>(
- 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_raw_socket(io_service&) constructor.
+ * constructed using the @c basic_raw_socket(io_context&) constructor.
*/
basic_raw_socket(basic_raw_socket&& other)
- : basic_socket<Protocol, RawSocketService>(
- BOOST_ASIO_MOVE_CAST(basic_raw_socket)(other))
+ : basic_socket<Protocol BOOST_ASIO_SVC_TARG>(std::move(other))
{
}
@@ -158,12 +161,11 @@ public:
* will occur.
*
* @note Following the move, the moved-from object is in the same state as if
- * constructed using the @c basic_raw_socket(io_service&) constructor.
+ * constructed using the @c basic_raw_socket(io_context&) constructor.
*/
basic_raw_socket& operator=(basic_raw_socket&& other)
{
- basic_socket<Protocol, RawSocketService>::operator=(
- BOOST_ASIO_MOVE_CAST(basic_raw_socket)(other));
+ basic_socket<Protocol BOOST_ASIO_SVC_TARG>::operator=(std::move(other));
return *this;
}
@@ -175,14 +177,12 @@ public:
* occur.
*
* @note Following the move, the moved-from object is in the same state as if
- * constructed using the @c basic_raw_socket(io_service&) constructor.
+ * constructed using the @c basic_raw_socket(io_context&) constructor.
*/
- template <typename Protocol1, typename RawSocketService1>
- basic_raw_socket(basic_raw_socket<Protocol1, RawSocketService1>&& other,
+ template <typename Protocol1 BOOST_ASIO_SVC_TPARAM1>
+ basic_raw_socket(basic_raw_socket<Protocol1 BOOST_ASIO_SVC_TARG1>&& other,
typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
- : basic_socket<Protocol, RawSocketService>(
- BOOST_ASIO_MOVE_CAST2(basic_raw_socket<
- Protocol1, RawSocketService1>)(other))
+ : basic_socket<Protocol BOOST_ASIO_SVC_TARG>(std::move(other))
{
}
@@ -194,20 +194,27 @@ public:
* will occur.
*
* @note Following the move, the moved-from object is in the same state as if
- * constructed using the @c basic_raw_socket(io_service&) constructor.
+ * constructed using the @c basic_raw_socket(io_context&) constructor.
*/
- template <typename Protocol1, typename RawSocketService1>
+ template <typename Protocol1 BOOST_ASIO_SVC_TPARAM1>
typename enable_if<is_convertible<Protocol1, Protocol>::value,
basic_raw_socket>::type& operator=(
- basic_raw_socket<Protocol1, RawSocketService1>&& other)
+ basic_raw_socket<Protocol1 BOOST_ASIO_SVC_TARG1>&& other)
{
- basic_socket<Protocol, RawSocketService>::operator=(
- BOOST_ASIO_MOVE_CAST2(basic_raw_socket<
- Protocol1, RawSocketService1>)(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_raw_socket()
+ {
+ }
+
/// Send some data on a connected socket.
/**
* This function is used to send data on the raw socket. The function call
@@ -310,7 +317,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 raw
@@ -335,8 +342,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.
@@ -361,7 +378,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 raw
@@ -378,8 +395,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 raw data to the specified endpoint.
@@ -493,7 +520,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:
@@ -518,8 +545,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_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.
@@ -547,7 +584,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,
@@ -560,9 +597,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.
@@ -674,7 +722,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
@@ -700,8 +748,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.
@@ -726,7 +784,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
@@ -743,8 +801,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 raw data with the endpoint of the sender.
@@ -861,7 +929,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
@@ -883,9 +951,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.
@@ -915,7 +994,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,
@@ -928,9 +1007,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)
}
};