10ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
20ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// detail/task_io_service_operation.hpp
30ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
50ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
60ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
70ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// Distributed under the Boost Software License, Version 1.0. (See accompanying
80ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
90ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
100ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
110ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#ifndef ASIO_DETAIL_TASK_IO_SERVICE_OPERATION_HPP
120ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#define ASIO_DETAIL_TASK_IO_SERVICE_OPERATION_HPP
130ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
140ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
150ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/error_code.hpp"
160ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/handler_tracking.hpp"
170ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/op_queue.hpp"
180ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
190ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/push_options.hpp"
200ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
210ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffienamespace asio {
220ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffienamespace detail {
230ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
240ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieclass task_io_service;
250ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
260ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// Base class for all operations. A function pointer is used instead of virtual
270ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// functions to avoid the associated overhead.
280ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieclass task_io_service_operation ASIO_INHERIT_TRACKED_HANDLER
290ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
300ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffiepublic:
310ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void complete(task_io_service& owner,
320ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      const asio::error_code& ec, std::size_t bytes_transferred)
330ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
340ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    func_(&owner, this, ec, bytes_transferred);
350ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
360ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
370ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void destroy()
380ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
390ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    func_(0, this, asio::error_code(), 0);
400ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
410ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
420ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieprotected:
430ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  typedef void (*func_type)(task_io_service*,
440ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      task_io_service_operation*,
450ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      const asio::error_code&, std::size_t);
460ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
470ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  task_io_service_operation(func_type func)
480ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    : next_(0),
490ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      func_(func),
500ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      task_result_(0)
510ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
520ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
530ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
540ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Prevents deletion through this type.
550ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  ~task_io_service_operation()
560ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
570ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
580ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
590ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieprivate:
600ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  friend class op_queue_access;
610ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  task_io_service_operation* next_;
620ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  func_type func_;
630ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieprotected:
640ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  friend class task_io_service;
650ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  unsigned int task_result_; // Passed into bytes transferred.
660ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie};
670ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
680ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie} // namespace detail
690ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie} // namespace asio
700ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
710ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/pop_options.hpp"
720ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
730ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#endif // ASIO_DETAIL_TASK_IO_SERVICE_OPERATION_HPP
74