task_io_service_operation.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // detail/task_io_service_operation.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2013 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_TASK_IO_SERVICE_OPERATION_HPP
  11. #define BOOST_ASIO_DETAIL_TASK_IO_SERVICE_OPERATION_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/system/error_code.hpp>
  16. #include <boost/asio/detail/handler_tracking.hpp>
  17. #include <boost/asio/detail/op_queue.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace detail {
  22. class task_io_service;
  23. // Base class for all operations. A function pointer is used instead of virtual
  24. // functions to avoid the associated overhead.
  25. class task_io_service_operation BOOST_ASIO_INHERIT_TRACKED_HANDLER
  26. {
  27. public:
  28. void complete(task_io_service& owner,
  29. const boost::system::error_code& ec, std::size_t bytes_transferred)
  30. {
  31. func_(&owner, this, ec, bytes_transferred);
  32. }
  33. void destroy()
  34. {
  35. func_(0, this, boost::system::error_code(), 0);
  36. }
  37. protected:
  38. typedef void (*func_type)(task_io_service*,
  39. task_io_service_operation*,
  40. const boost::system::error_code&, std::size_t);
  41. task_io_service_operation(func_type func)
  42. : next_(0),
  43. func_(func),
  44. task_result_(0)
  45. {
  46. }
  47. // Prevents deletion through this type.
  48. ~task_io_service_operation()
  49. {
  50. }
  51. private:
  52. friend class op_queue_access;
  53. task_io_service_operation* next_;
  54. func_type func_;
  55. protected:
  56. friend class task_io_service;
  57. unsigned int task_result_; // Passed into bytes transferred.
  58. };
  59. } // namespace detail
  60. } // namespace asio
  61. } // namespace boost
  62. #include <boost/asio/detail/pop_options.hpp>
  63. #endif // BOOST_ASIO_DETAIL_TASK_IO_SERVICE_OPERATION_HPP