reactor_op.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // detail/reactor_op.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 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(perform_func_type perform_func, func_type complete_func)
  40. : operation(complete_func),
  41. bytes_transferred_(0),
  42. perform_func_(perform_func)
  43. {
  44. }
  45. private:
  46. perform_func_type perform_func_;
  47. };
  48. } // namespace detail
  49. } // namespace asio
  50. } // namespace boost
  51. #include <boost/asio/detail/pop_options.hpp>
  52. #endif // BOOST_ASIO_DETAIL_REACTOR_OP_HPP