1 // 2 // detail/scheduler_operation.hpp 3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4 // 5 // Copyright (c) 2003-2019 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 11 #ifndef BOOST_ASIO_DETAIL_SCHEDULER_OPERATION_HPP 12 #define BOOST_ASIO_DETAIL_SCHEDULER_OPERATION_HPP 13 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 15 # pragma once 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 17 18 #include <boost/system/error_code.hpp> 19 #include <boost/asio/detail/handler_tracking.hpp> 20 #include <boost/asio/detail/op_queue.hpp> 21 22 #include <boost/asio/detail/push_options.hpp> 23 24 namespace boost { 25 namespace asio { 26 namespace detail { 27 28 class scheduler; 29 30 // Base class for all operations. A function pointer is used instead of virtual 31 // functions to avoid the associated overhead. 32 class scheduler_operation BOOST_ASIO_INHERIT_TRACKED_HANDLER 33 { 34 public: 35 typedef scheduler_operation operation_type; 36 complete(void * owner,const boost::system::error_code & ec,std::size_t bytes_transferred)37 void complete(void* owner, const boost::system::error_code& ec, 38 std::size_t bytes_transferred) 39 { 40 func_(owner, this, ec, bytes_transferred); 41 } 42 destroy()43 void destroy() 44 { 45 func_(0, this, boost::system::error_code(), 0); 46 } 47 48 protected: 49 typedef void (*func_type)(void*, 50 scheduler_operation*, 51 const boost::system::error_code&, std::size_t); 52 scheduler_operation(func_type func)53 scheduler_operation(func_type func) 54 : next_(0), 55 func_(func), 56 task_result_(0) 57 { 58 } 59 60 // Prevents deletion through this type. ~scheduler_operation()61 ~scheduler_operation() 62 { 63 } 64 65 private: 66 friend class op_queue_access; 67 scheduler_operation* next_; 68 func_type func_; 69 protected: 70 friend class scheduler; 71 unsigned int task_result_; // Passed into bytes transferred. 72 }; 73 74 } // namespace detail 75 } // namespace asio 76 } // namespace boost 77 78 #include <boost/asio/detail/pop_options.hpp> 79 80 #endif // BOOST_ASIO_DETAIL_SCHEDULER_OPERATION_HPP 81