/src/contrib/boost/asio/detail/null_buffers_op.hpp

http://pythonocc.googlecode.com/ · C++ Header · 79 lines · 49 code · 13 blank · 17 comment · 2 complexity · e9e4c4040111e22d91391f9249f10b6a MD5 · raw file

  1. //
  2. // null_buffers_op.hpp
  3. // ~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2010 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. #ifndef BOOST_ASIO_DETAIL_NULL_BUFFERS_OP_HPP
  11. #define BOOST_ASIO_DETAIL_NULL_BUFFERS_OP_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/push_options.hpp>
  16. #include <boost/asio/detail/fenced_block.hpp>
  17. #include <boost/asio/detail/handler_alloc_helpers.hpp>
  18. #include <boost/asio/detail/handler_invoke_helpers.hpp>
  19. #include <boost/asio/detail/reactor_op.hpp>
  20. namespace boost {
  21. namespace asio {
  22. namespace detail {
  23. template <typename Handler>
  24. class null_buffers_op : public reactor_op
  25. {
  26. public:
  27. null_buffers_op(Handler handler)
  28. : reactor_op(&null_buffers_op::do_perform, &null_buffers_op::do_complete),
  29. handler_(handler)
  30. {
  31. }
  32. static bool do_perform(reactor_op*)
  33. {
  34. return true;
  35. }
  36. static void do_complete(io_service_impl* owner, operation* base,
  37. boost::system::error_code /*ec*/, std::size_t /*bytes_transferred*/)
  38. {
  39. // Take ownership of the handler object.
  40. null_buffers_op* o(static_cast<null_buffers_op*>(base));
  41. typedef handler_alloc_traits<Handler, null_buffers_op> alloc_traits;
  42. handler_ptr<alloc_traits> ptr(o->handler_, o);
  43. // Make the upcall if required.
  44. if (owner)
  45. {
  46. // Make a copy of the handler so that the memory can be deallocated
  47. // before the upcall is made. Even if we're not about to make an upcall,
  48. // a sub-object of the handler may be the true owner of the memory
  49. // associated with the handler. Consequently, a local copy of the handler
  50. // is required to ensure that any owning sub-object remains valid until
  51. // after we have deallocated the memory here.
  52. detail::binder2<Handler, boost::system::error_code, std::size_t>
  53. handler(o->handler_, o->ec_, o->bytes_transferred_);
  54. ptr.reset();
  55. boost::asio::detail::fenced_block b;
  56. boost_asio_handler_invoke_helpers::invoke(handler, handler);
  57. }
  58. }
  59. private:
  60. Handler handler_;
  61. };
  62. } // namespace detail
  63. } // namespace asio
  64. } // namespace boost
  65. #include <boost/asio/detail/pop_options.hpp>
  66. #endif // BOOST_ASIO_DETAIL_NULL_BUFFERS_OP_HPP