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 BOOST_ASIO_DETAIL_TASK_IO_SERVICE_OPERATION_HPP
12#define BOOST_ASIO_DETAIL_TASK_IO_SERVICE_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
24namespace boost {
25namespace asio {
26namespace detail {
27
28class task_io_service;
29
30// Base class for all operations. A function pointer is used instead of virtual
31// functions to avoid the associated overhead.
32class task_io_service_operation BOOST_ASIO_INHERIT_TRACKED_HANDLER
33{
34public:
35 void complete(task_io_service& owner,
36 const boost::system::error_code& ec, std::size_t bytes_transferred)
37 {
38 func_(&owner, this, ec, bytes_transferred);
39 }
40
41 void destroy()
42 {
43 func_(0, this, boost::system::error_code(), 0);
44 }
45
46protected:
47 typedef void (*func_type)(task_io_service*,
48 task_io_service_operation*,
49 const boost::system::error_code&, std::size_t);
50
51 task_io_service_operation(func_type func)
52 : next_(0),
53 func_(func),
54 task_result_(0)
55 {
56 }
57
58 // Prevents deletion through this type.
59 ~task_io_service_operation()
60 {
61 }
62
63private:
64 friend class op_queue_access;
65 task_io_service_operation* next_;
66 func_type func_;
67protected:
68 friend class task_io_service;
69 unsigned int task_result_; // Passed into bytes transferred.
70};
71
72} // namespace detail
73} // namespace asio
74} // namespace boost
75
76#include <boost/asio/detail/pop_options.hpp>
77
78#endif // BOOST_ASIO_DETAIL_TASK_IO_SERVICE_OPERATION_HPP
79