win_iocp_operation.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // win_iocp_operation.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2010 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 ASIO_DETAIL_WIN_IOCP_OPERATION_HPP
  11. #define ASIO_DETAIL_WIN_IOCP_OPERATION_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/push_options.hpp"
  16. #include "asio/detail/win_iocp_io_service_fwd.hpp"
  17. #if defined(ASIO_HAS_IOCP)
  18. #include "asio/error_code.hpp"
  19. #include "asio/detail/op_queue.hpp"
  20. namespace asio {
  21. namespace detail {
  22. // Base class for all operations. A function pointer is used instead of virtual
  23. // functions to avoid the associated overhead.
  24. class win_iocp_operation
  25. : public OVERLAPPED
  26. {
  27. public:
  28. void complete(win_iocp_io_service& owner,
  29. const asio::error_code& ec = asio::error_code(),
  30. std::size_t bytes_transferred = 0)
  31. {
  32. func_(&owner, this, ec, bytes_transferred);
  33. }
  34. void destroy()
  35. {
  36. func_(0, this, asio::error_code(), 0);
  37. }
  38. protected:
  39. typedef void (*func_type)(win_iocp_io_service*,
  40. win_iocp_operation*, asio::error_code, std::size_t);
  41. win_iocp_operation(func_type func)
  42. : next_(0),
  43. func_(func)
  44. {
  45. reset();
  46. }
  47. // Prevents deletion through this type.
  48. ~win_iocp_operation()
  49. {
  50. }
  51. void reset()
  52. {
  53. Internal = 0;
  54. InternalHigh = 0;
  55. Offset = 0;
  56. OffsetHigh = 0;
  57. hEvent = 0;
  58. ready_ = 0;
  59. }
  60. private:
  61. friend class op_queue_access;
  62. friend class win_iocp_io_service;
  63. win_iocp_operation* next_;
  64. func_type func_;
  65. long ready_;
  66. };
  67. } // namespace detail
  68. } // namespace asio
  69. #endif // defined(ASIO_HAS_IOCP)
  70. #include "asio/detail/pop_options.hpp"
  71. #endif // ASIO_DETAIL_WIN_IOCP_OPERATION_HPP