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