win_iocp_operation.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // detail/win_iocp_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. #ifndef BOOST_ASIO_DETAIL_WIN_IOCP_OPERATION_HPP
  11. #define BOOST_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 <boost/asio/detail/config.hpp>
  16. #if defined(BOOST_ASIO_HAS_IOCP)
  17. #include <boost/asio/detail/handler_tracking.hpp>
  18. #include <boost/asio/detail/op_queue.hpp>
  19. #include <boost/asio/detail/socket_types.hpp>
  20. #include <boost/system/error_code.hpp>
  21. #include <boost/asio/detail/push_options.hpp>
  22. namespace boost {
  23. namespace asio {
  24. namespace detail {
  25. class win_iocp_io_context;
  26. // Base class for all operations. A function pointer is used instead of virtual
  27. // functions to avoid the associated overhead.
  28. class win_iocp_operation
  29. : public OVERLAPPED
  30. BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER
  31. {
  32. public:
  33. typedef win_iocp_operation operation_type;
  34. void complete(void* owner, const boost::system::error_code& ec,
  35. std::size_t bytes_transferred)
  36. {
  37. func_(owner, this, ec, bytes_transferred);
  38. }
  39. void destroy()
  40. {
  41. func_(0, this, boost::system::error_code(), 0);
  42. }
  43. protected:
  44. typedef void (*func_type)(
  45. void*, win_iocp_operation*,
  46. const boost::system::error_code&, std::size_t);
  47. win_iocp_operation(func_type func)
  48. : next_(0),
  49. func_(func)
  50. {
  51. reset();
  52. }
  53. // Prevents deletion through this type.
  54. ~win_iocp_operation()
  55. {
  56. }
  57. void reset()
  58. {
  59. Internal = 0;
  60. InternalHigh = 0;
  61. Offset = 0;
  62. OffsetHigh = 0;
  63. hEvent = 0;
  64. ready_ = 0;
  65. }
  66. private:
  67. friend class op_queue_access;
  68. friend class win_iocp_io_context;
  69. win_iocp_operation* next_;
  70. func_type func_;
  71. long ready_;
  72. };
  73. } // namespace detail
  74. } // namespace asio
  75. } // namespace boost
  76. #include <boost/asio/detail/pop_options.hpp>
  77. #endif // defined(BOOST_ASIO_HAS_IOCP)
  78. #endif // BOOST_ASIO_DETAIL_WIN_IOCP_OPERATION_HPP