reactor_op.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // reactor_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 ASIO_DETAIL_REACTOR_OP_HPP
  11. #define ASIO_DETAIL_REACTOR_OP_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/detail/operation.hpp"
  17. namespace asio {
  18. namespace detail {
  19. class reactor_op
  20. : public operation
  21. {
  22. public:
  23. // The error code to be passed to the completion handler.
  24. asio::error_code ec_;
  25. // The number of bytes transferred, to be passed to the completion handler.
  26. std::size_t bytes_transferred_;
  27. // Perform the operation. Returns true if it is finished.
  28. bool perform()
  29. {
  30. return perform_func_(this);
  31. }
  32. protected:
  33. typedef bool (*perform_func_type)(reactor_op*);
  34. reactor_op(perform_func_type perform_func, func_type complete_func)
  35. : operation(complete_func),
  36. bytes_transferred_(0),
  37. perform_func_(perform_func)
  38. {
  39. }
  40. private:
  41. perform_func_type perform_func_;
  42. };
  43. } // namespace detail
  44. } // namespace asio
  45. #include "asio/detail/pop_options.hpp"
  46. #endif // ASIO_DETAIL_REACTOR_OP_HPP