task_io_service_operation.hpp 1.8 KB

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