Deprecate io_service members dispatch(), post() and wrap().
This commit is contained in:
parent
4159db3ff6
commit
ebc8b148ba
@ -18,6 +18,7 @@
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/detail/fenced_block.hpp"
|
||||
#include "asio/detail/handler_alloc_helpers.hpp"
|
||||
#include "asio/detail/handler_invoke_helpers.hpp"
|
||||
#include "asio/detail/scheduler_operation.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
@ -63,7 +64,7 @@ public:
|
||||
{
|
||||
fenced_block b(fenced_block::half);
|
||||
ASIO_HANDLER_INVOCATION_BEGIN(());
|
||||
handler();
|
||||
asio_handler_invoke_helpers::invoke(handler, handler);
|
||||
ASIO_HANDLER_INVOCATION_END;
|
||||
}
|
||||
}
|
||||
|
@ -24,45 +24,22 @@
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
// A special type meeting the Executor requirements that is used to indicate
|
||||
// that a handler should be executed using the old invocation hook. The type is
|
||||
// not used at runtime, but only at compile time to distinguish whether a
|
||||
// handler provides its own associated executor type or not.
|
||||
class hook_executor
|
||||
{
|
||||
public:
|
||||
execution_context& context() ASIO_NOEXCEPT
|
||||
{
|
||||
return system_executor().context();
|
||||
}
|
||||
|
||||
void on_work_started() ASIO_NOEXCEPT {}
|
||||
void on_work_finished() ASIO_NOEXCEPT {}
|
||||
|
||||
template <typename Function, typename Allocator>
|
||||
void dispatch(ASIO_MOVE_ARG(Function), const Allocator&) {}
|
||||
template <typename Function, typename Allocator>
|
||||
void post(ASIO_MOVE_ARG(Function), const Allocator&) {}
|
||||
template <typename Function, typename Allocator>
|
||||
void defer(ASIO_MOVE_ARG(Function), const Allocator&) {}
|
||||
};
|
||||
|
||||
// A helper class template to allow completion handlers to be dispatched
|
||||
// through either the new executors framework or the old invocaton hook. The
|
||||
// primary template uses the new executors framework.
|
||||
template <typename Handler, typename Executor
|
||||
= typename associated_executor<Handler, hook_executor>::type>
|
||||
= typename associated_executor<Handler>::type>
|
||||
class handler_work
|
||||
{
|
||||
public:
|
||||
explicit handler_work(Handler& handler) ASIO_NOEXCEPT
|
||||
: executor_(associated_executor<Handler, hook_executor>::get(handler))
|
||||
: executor_(associated_executor<Handler>::get(handler))
|
||||
{
|
||||
}
|
||||
|
||||
static void start(Handler& handler) ASIO_NOEXCEPT
|
||||
{
|
||||
Executor ex(associated_executor<Handler, hook_executor>::get(handler));
|
||||
Executor ex(associated_executor<Handler>::get(handler));
|
||||
ex.on_work_started();
|
||||
}
|
||||
|
||||
@ -83,12 +60,15 @@ private:
|
||||
handler_work(const handler_work&);
|
||||
handler_work& operator=(const handler_work&);
|
||||
|
||||
typename associated_executor<Handler, hook_executor>::type executor_;
|
||||
typename associated_executor<Handler>::type executor_;
|
||||
};
|
||||
|
||||
// This specialisation dispatches a handler through the old invocation hook.
|
||||
// The specialisation is not strictly required for correctness, as the
|
||||
// system_executor will dispatch through the hook anyway. However, by doing
|
||||
// this we avoid an extra copy of the handler.
|
||||
template <typename Handler>
|
||||
class handler_work<Handler, hook_executor>
|
||||
class handler_work<Handler, system_executor>
|
||||
{
|
||||
public:
|
||||
explicit handler_work(Handler&) ASIO_NOEXCEPT {}
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "asio/detail/call_stack.hpp"
|
||||
#include "asio/detail/fenced_block.hpp"
|
||||
#include "asio/detail/handler_invoke_helpers.hpp"
|
||||
#include "asio/detail/recycling_allocator.hpp"
|
||||
#include "asio/executor_work.hpp"
|
||||
|
||||
@ -106,7 +107,7 @@ void strand_executor_service::dispatch(const implementation_type& impl,
|
||||
if (call_stack<strand_impl>::contains(impl.get()))
|
||||
{
|
||||
fenced_block b(fenced_block::full);
|
||||
tmp();
|
||||
asio_handler_invoke_helpers::invoke(tmp, tmp);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -65,11 +65,11 @@ io_service::get_executor() ASIO_NOEXCEPT
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
inline void io_service::reset()
|
||||
{
|
||||
restart();
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
template <typename CompletionHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ())
|
||||
@ -143,6 +143,8 @@ io_service::wrap(Handler handler)
|
||||
return detail::wrapped_handler<io_service&, Handler>(*this, handler);
|
||||
}
|
||||
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
inline io_service&
|
||||
io_service::executor_type::context() ASIO_NOEXCEPT
|
||||
{
|
||||
@ -171,7 +173,7 @@ void io_service::executor_type::dispatch(
|
||||
if (io_service_.impl_.can_dispatch())
|
||||
{
|
||||
detail::fenced_block b(detail::fenced_block::full);
|
||||
tmp();
|
||||
asio_handler_invoke_helpers::invoke(tmp, tmp);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ void system_executor::dispatch(
|
||||
ASIO_MOVE_ARG(Function) f, const Allocator&)
|
||||
{
|
||||
typename decay<Function>::type tmp(ASIO_MOVE_CAST(Function)(f));
|
||||
tmp();
|
||||
asio_handler_invoke_helpers::invoke(tmp, tmp);
|
||||
}
|
||||
|
||||
template <typename Function, typename Allocator>
|
||||
|
@ -59,7 +59,7 @@ void thread_pool::executor_type::dispatch(
|
||||
if (pool_.scheduler_.can_dispatch())
|
||||
{
|
||||
detail::fenced_block b(detail::fenced_block::full);
|
||||
tmp();
|
||||
asio_handler_invoke_helpers::invoke(tmp, tmp);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -393,9 +393,9 @@ public:
|
||||
* the run(), run_one(), poll() or poll_one() functions.
|
||||
*/
|
||||
void reset();
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Request the io_service to invoke the given handler.
|
||||
/// (Deprecated: Use asio::dispatch().) Request the io_service to
|
||||
/// invoke the given handler.
|
||||
/**
|
||||
* This function is used to ask the io_service to execute the given handler.
|
||||
*
|
||||
@ -420,7 +420,8 @@ public:
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ())
|
||||
dispatch(ASIO_MOVE_ARG(CompletionHandler) handler);
|
||||
|
||||
/// Request the io_service to invoke the given handler and return immediately.
|
||||
/// (Deprecated: Use asio::post().) Request the io_service to invoke
|
||||
/// the given handler and return immediately.
|
||||
/**
|
||||
* This function is used to ask the io_service to execute the given handler,
|
||||
* but without allowing the io_service to call the handler from inside this
|
||||
@ -446,8 +447,8 @@ public:
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ())
|
||||
post(ASIO_MOVE_ARG(CompletionHandler) handler);
|
||||
|
||||
/// Create a new handler that automatically dispatches the wrapped handler
|
||||
/// on the io_service.
|
||||
/// (Deprecated: Use asio::wrap().) Create a new handler that
|
||||
/// automatically dispatches the wrapped handler on the io_service.
|
||||
/**
|
||||
* This function is used to create a new handler function object that, when
|
||||
* invoked, will automatically pass the wrapped handler to the io_service
|
||||
@ -475,6 +476,7 @@ public:
|
||||
detail::wrapped_handler<io_service&, Handler>
|
||||
#endif
|
||||
wrap(Handler handler);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
private:
|
||||
// Helper function to create the implementation.
|
||||
|
@ -34,12 +34,14 @@ public:
|
||||
|
||||
void write(const chat_message& msg)
|
||||
{
|
||||
io_service_.post(boost::bind(&chat_client::do_write, this, msg));
|
||||
asio::post(io_service_,
|
||||
boost::bind(&chat_client::do_write, this, msg));
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
io_service_.post(boost::bind(&chat_client::do_close, this));
|
||||
asio::post(io_service_,
|
||||
boost::bind(&chat_client::do_close, this));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -132,7 +132,7 @@ int main()
|
||||
handler_priority_queue pri_queue;
|
||||
|
||||
// Post a completion handler to be run immediately.
|
||||
io_service.post(pri_queue.wrap(0, low_priority_handler));
|
||||
asio::post(io_service, pri_queue.wrap(0, low_priority_handler));
|
||||
|
||||
// Start an asynchronous accept that will complete immediately.
|
||||
tcp::endpoint endpoint(asio::ip::address_v4::loopback(), 0);
|
||||
|
@ -91,7 +91,7 @@ public:
|
||||
void use_file(impl_type& /*impl*/, const std::string& file)
|
||||
{
|
||||
// Pass the work of opening the file to the background thread.
|
||||
work_io_service_.post(boost::bind(
|
||||
asio::post(work_io_service_, boost::bind(
|
||||
&logger_service::use_file_impl, this, file));
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ public:
|
||||
os << impl->identifier << ": " << message;
|
||||
|
||||
// Pass the work of opening the file to the background thread.
|
||||
work_io_service_.post(boost::bind(
|
||||
asio::post(work_io_service_, boost::bind(
|
||||
&logger_service::log_impl, this, os.str()));
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
|
||||
void write(const chat_message& msg)
|
||||
{
|
||||
io_service_.post(
|
||||
asio::post(io_service_,
|
||||
[this, msg]()
|
||||
{
|
||||
bool write_in_progress = !write_msgs_.empty();
|
||||
@ -46,7 +46,7 @@ public:
|
||||
|
||||
void close()
|
||||
{
|
||||
io_service_.post([this]() { socket_.close(); });
|
||||
asio::post(io_service_, [this]() { socket_.close(); });
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
io_service_.post(boost::bind(&session::destroy, this));
|
||||
asio::post(io_service_, boost::bind(&session::destroy, this));
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ public:
|
||||
}
|
||||
|
||||
if (op_count_ == 0)
|
||||
io_service_.post(boost::bind(&session::destroy, this));
|
||||
asio::post(io_service_, boost::bind(&session::destroy, this));
|
||||
}
|
||||
|
||||
void handle_write(const asio::error_code& err)
|
||||
@ -119,7 +119,7 @@ public:
|
||||
}
|
||||
|
||||
if (op_count_ == 0)
|
||||
io_service_.post(boost::bind(&session::destroy, this));
|
||||
asio::post(io_service_, boost::bind(&session::destroy, this));
|
||||
}
|
||||
|
||||
static void destroy(session* s)
|
||||
|
Loading…
Reference in New Issue
Block a user