task_io_service_operation.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // task_io_service_operation.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 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/detail/push_options.hpp"
  16. #include "asio/error_code.hpp"
  17. #include "asio/detail/op_queue.hpp"
  18. #include "asio/detail/task_io_service_fwd.hpp"
  19. namespace asio {
  20. namespace detail {
  21. // Base class for all operations. A function pointer is used instead of virtual
  22. // functions to avoid the associated overhead.
  23. template <typename Task>
  24. class task_io_service_operation
  25. {
  26. public:
  27. void complete(task_io_service<Task>& owner)
  28. {
  29. func_(&owner, this, asio::error_code(), 0);
  30. }
  31. void destroy()
  32. {
  33. func_(0, this, asio::error_code(), 0);
  34. }
  35. protected:
  36. typedef void (*func_type)(task_io_service<Task>*,
  37. task_io_service_operation*, asio::error_code, std::size_t);
  38. task_io_service_operation(func_type func)
  39. : next_(0),
  40. func_(func)
  41. {
  42. }
  43. // Prevents deletion through this type.
  44. ~task_io_service_operation()
  45. {
  46. }
  47. private:
  48. friend class op_queue_access;
  49. task_io_service_operation* next_;
  50. func_type func_;
  51. };
  52. } // namespace detail
  53. } // namespace asio
  54. #include "asio/detail/pop_options.hpp"
  55. #endif // ASIO_DETAIL_TASK_IO_SERVICE_OPERATION_HPP