reactor_op.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // detail/reactor_op.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 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_REACTOR_OP_HPP
  11. #define BOOST_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 <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/operation.hpp>
  17. #include <boost/asio/detail/push_options.hpp>
  18. namespace boost {
  19. namespace asio {
  20. namespace detail {
  21. class reactor_op
  22. : public operation
  23. {
  24. public:
  25. // The error code to be passed to the completion handler.
  26. boost::system::error_code ec_;
  27. // The number of bytes transferred, to be passed to the completion handler.
  28. std::size_t bytes_transferred_;
  29. // Status returned by perform function. May be used to decide whether it is
  30. // worth performing more operations on the descriptor immediately.
  31. enum status { not_done, done, done_and_exhausted };
  32. // Perform the operation. Returns true if it is finished.
  33. status perform()
  34. {
  35. return perform_func_(this);
  36. }
  37. protected:
  38. typedef status (*perform_func_type)(reactor_op*);
  39. reactor_op(const boost::system::error_code& success_ec,
  40. perform_func_type perform_func, func_type complete_func)
  41. : operation(complete_func),
  42. ec_(success_ec),
  43. bytes_transferred_(0),
  44. perform_func_(perform_func)
  45. {
  46. }
  47. private:
  48. perform_func_type perform_func_;
  49. };
  50. } // namespace detail
  51. } // namespace asio
  52. } // namespace boost
  53. #include <boost/asio/detail/pop_options.hpp>
  54. #endif // BOOST_ASIO_DETAIL_REACTOR_OP_HPP