File indexing completed on 2025-01-18 09:28:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_ASIO_DETAIL_WIN_OBJECT_HANDLE_SERVICE_HPP
0013 #define BOOST_ASIO_DETAIL_WIN_OBJECT_HANDLE_SERVICE_HPP
0014
0015 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0016 # pragma once
0017 #endif
0018
0019 #include <boost/asio/detail/config.hpp>
0020
0021 #if defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE)
0022
0023 #include <boost/asio/detail/memory.hpp>
0024 #include <boost/asio/detail/wait_handler.hpp>
0025 #include <boost/asio/error.hpp>
0026 #include <boost/asio/execution_context.hpp>
0027
0028 #if defined(BOOST_ASIO_HAS_IOCP)
0029 # include <boost/asio/detail/win_iocp_io_context.hpp>
0030 #else
0031 # include <boost/asio/detail/scheduler.hpp>
0032 #endif
0033
0034 #include <boost/asio/detail/push_options.hpp>
0035
0036 namespace boost {
0037 namespace asio {
0038 namespace detail {
0039
0040 class win_object_handle_service :
0041 public execution_context_service_base<win_object_handle_service>
0042 {
0043 public:
0044
0045 typedef HANDLE native_handle_type;
0046
0047
0048 class implementation_type
0049 {
0050 public:
0051
0052 implementation_type()
0053 : handle_(INVALID_HANDLE_VALUE),
0054 wait_handle_(INVALID_HANDLE_VALUE),
0055 owner_(0),
0056 next_(0),
0057 prev_(0)
0058 {
0059 }
0060
0061 private:
0062
0063 friend class win_object_handle_service;
0064
0065
0066
0067 native_handle_type handle_;
0068
0069
0070
0071 HANDLE wait_handle_;
0072
0073
0074
0075
0076 op_queue<wait_op> op_queue_;
0077
0078
0079 win_object_handle_service* owner_;
0080
0081
0082
0083 implementation_type* next_;
0084 implementation_type* prev_;
0085 };
0086
0087
0088 BOOST_ASIO_DECL win_object_handle_service(execution_context& context);
0089
0090
0091 BOOST_ASIO_DECL void shutdown();
0092
0093
0094 BOOST_ASIO_DECL void construct(implementation_type& impl);
0095
0096
0097 BOOST_ASIO_DECL void move_construct(implementation_type& impl,
0098 implementation_type& other_impl);
0099
0100
0101 BOOST_ASIO_DECL void move_assign(implementation_type& impl,
0102 win_object_handle_service& other_service,
0103 implementation_type& other_impl);
0104
0105
0106 BOOST_ASIO_DECL void destroy(implementation_type& impl);
0107
0108
0109 BOOST_ASIO_DECL boost::system::error_code assign(implementation_type& impl,
0110 const native_handle_type& handle, boost::system::error_code& ec);
0111
0112
0113 bool is_open(const implementation_type& impl) const
0114 {
0115 return impl.handle_ != INVALID_HANDLE_VALUE && impl.handle_ != 0;
0116 }
0117
0118
0119 BOOST_ASIO_DECL boost::system::error_code close(implementation_type& impl,
0120 boost::system::error_code& ec);
0121
0122
0123 native_handle_type native_handle(const implementation_type& impl) const
0124 {
0125 return impl.handle_;
0126 }
0127
0128
0129 BOOST_ASIO_DECL boost::system::error_code cancel(implementation_type& impl,
0130 boost::system::error_code& ec);
0131
0132
0133 BOOST_ASIO_DECL void wait(implementation_type& impl,
0134 boost::system::error_code& ec);
0135
0136
0137 template <typename Handler, typename IoExecutor>
0138 void async_wait(implementation_type& impl,
0139 Handler& handler, const IoExecutor& io_ex)
0140 {
0141
0142 typedef wait_handler<Handler, IoExecutor> op;
0143 typename op::ptr p = { boost::asio::detail::addressof(handler),
0144 op::ptr::allocate(handler), 0 };
0145 p.p = new (p.v) op(handler, io_ex);
0146
0147 BOOST_ASIO_HANDLER_CREATION((scheduler_.context(), *p.p, "object_handle",
0148 &impl, reinterpret_cast<uintmax_t>(impl.wait_handle_), "async_wait"));
0149
0150 start_wait_op(impl, p.p);
0151 p.v = p.p = 0;
0152 }
0153
0154 private:
0155
0156 BOOST_ASIO_DECL void start_wait_op(implementation_type& impl, wait_op* op);
0157
0158
0159 BOOST_ASIO_DECL void register_wait_callback(
0160 implementation_type& impl, mutex::scoped_lock& lock);
0161
0162
0163 static BOOST_ASIO_DECL VOID CALLBACK wait_callback(
0164 PVOID param, BOOLEAN timeout);
0165
0166
0167 #if defined(BOOST_ASIO_HAS_IOCP)
0168 typedef class win_iocp_io_context scheduler_impl;
0169 #else
0170 typedef class scheduler scheduler_impl;
0171 #endif
0172 scheduler_impl& scheduler_;
0173
0174
0175 mutex mutex_;
0176
0177
0178 implementation_type* impl_list_;
0179
0180
0181 bool shutdown_;
0182 };
0183
0184 }
0185 }
0186 }
0187
0188 #include <boost/asio/detail/pop_options.hpp>
0189
0190 #if defined(BOOST_ASIO_HEADER_ONLY)
0191 # include <boost/asio/detail/impl/win_object_handle_service.ipp>
0192 #endif
0193
0194 #endif
0195
0196 #endif