5
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11
#ifndef BOOST_ASIO_WINDOWS_BASIC_HANDLE_HPP
12
#define BOOST_ASIO_WINDOWS_BASIC_HANDLE_HPP
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
#include <boost/asio/detail/push_options.hpp>
20
#include <boost/asio/detail/push_options.hpp>
21
#include <boost/config.hpp>
22
#include <boost/asio/detail/pop_options.hpp>
24
#include <boost/asio/basic_io_object.hpp>
25
#include <boost/asio/error.hpp>
26
#include <boost/asio/detail/throw_error.hpp>
32
/// Provides Windows handle functionality.
34
* The windows::basic_handle class template provides the ability to wrap a
38
* @e Distinct @e objects: Safe.@n
39
* @e Shared @e objects: Unsafe.
41
template <typename HandleService>
43
: public basic_io_object<HandleService>
46
/// The native representation of a handle.
47
typedef typename HandleService::native_type native_type;
49
/// A basic_handle is always the lowest layer.
50
typedef basic_handle<HandleService> lowest_layer_type;
52
/// Construct a basic_handle without opening it.
54
* This constructor creates a handle without opening it.
56
* @param io_service The io_service object that the handle will use to
57
* dispatch handlers for any asynchronous operations performed on the handle.
59
explicit basic_handle(boost::asio::io_service& io_service)
60
: basic_io_object<HandleService>(io_service)
64
/// Construct a basic_handle on an existing native handle.
66
* This constructor creates a handle object to hold an existing native handle.
68
* @param io_service The io_service object that the handle will use to
69
* dispatch handlers for any asynchronous operations performed on the handle.
71
* @param native_handle A native handle.
73
* @throws boost::system::system_error Thrown on failure.
75
basic_handle(boost::asio::io_service& io_service,
76
const native_type& native_handle)
77
: basic_io_object<HandleService>(io_service)
79
boost::system::error_code ec;
80
this->service.assign(this->implementation, native_handle, ec);
81
boost::asio::detail::throw_error(ec);
84
/// Get a reference to the lowest layer.
86
* This function returns a reference to the lowest layer in a stack of
87
* layers. Since a basic_handle cannot contain any further layers, it simply
88
* returns a reference to itself.
90
* @return A reference to the lowest layer in the stack of layers. Ownership
91
* is not transferred to the caller.
93
lowest_layer_type& lowest_layer()
98
/// Get a const reference to the lowest layer.
100
* This function returns a const reference to the lowest layer in a stack of
101
* layers. Since a basic_handle cannot contain any further layers, it simply
102
* returns a reference to itself.
104
* @return A const reference to the lowest layer in the stack of layers.
105
* Ownership is not transferred to the caller.
107
const lowest_layer_type& lowest_layer() const
112
/// Assign an existing native handle to the handle.
114
* This function opens the handle to hold an existing native handle.
116
* @param native_handle A native handle.
118
* @throws boost::system::system_error Thrown on failure.
120
void assign(const native_type& native_handle)
122
boost::system::error_code ec;
123
this->service.assign(this->implementation, native_handle, ec);
124
boost::asio::detail::throw_error(ec);
127
/// Assign an existing native handle to the handle.
129
* This function opens the handle to hold an existing native handle.
131
* @param native_handle A native handle.
133
* @param ec Set to indicate what error occurred, if any.
135
boost::system::error_code assign(const native_type& native_handle,
136
boost::system::error_code& ec)
138
return this->service.assign(this->implementation, native_handle, ec);
141
/// Determine whether the handle is open.
144
return this->service.is_open(this->implementation);
147
/// Close the handle.
149
* This function is used to close the handle. Any asynchronous read or write
150
* operations will be cancelled immediately, and will complete with the
151
* boost::asio::error::operation_aborted error.
153
* @throws boost::system::system_error Thrown on failure.
157
boost::system::error_code ec;
158
this->service.close(this->implementation, ec);
159
boost::asio::detail::throw_error(ec);
162
/// Close the handle.
164
* This function is used to close the handle. Any asynchronous read or write
165
* operations will be cancelled immediately, and will complete with the
166
* boost::asio::error::operation_aborted error.
168
* @param ec Set to indicate what error occurred, if any.
170
boost::system::error_code close(boost::system::error_code& ec)
172
return this->service.close(this->implementation, ec);
175
/// Get the native handle representation.
177
* This function may be used to obtain the underlying representation of the
178
* handle. This is intended to allow access to native handle functionality
179
* that is not otherwise provided.
183
return this->service.native(this->implementation);
186
/// Cancel all asynchronous operations associated with the handle.
188
* This function causes all outstanding asynchronous read or write operations
189
* to finish immediately, and the handlers for cancelled operations will be
190
* passed the boost::asio::error::operation_aborted error.
192
* @throws boost::system::system_error Thrown on failure.
196
boost::system::error_code ec;
197
this->service.cancel(this->implementation, ec);
198
boost::asio::detail::throw_error(ec);
201
/// Cancel all asynchronous operations associated with the handle.
203
* This function causes all outstanding asynchronous read or write operations
204
* to finish immediately, and the handlers for cancelled operations will be
205
* passed the boost::asio::error::operation_aborted error.
207
* @param ec Set to indicate what error occurred, if any.
209
boost::system::error_code cancel(boost::system::error_code& ec)
211
return this->service.cancel(this->implementation, ec);
215
/// Protected destructor to prevent deletion through this type.
221
} // namespace windows
225
#include <boost/asio/detail/pop_options.hpp>
227
#endif // BOOST_ASIO_WINDOWS_BASIC_HANDLE_HPP
5
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11
#ifndef BOOST_ASIO_WINDOWS_BASIC_HANDLE_HPP
12
#define BOOST_ASIO_WINDOWS_BASIC_HANDLE_HPP
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
#include <boost/asio/detail/push_options.hpp>
20
#include <boost/asio/detail/push_options.hpp>
21
#include <boost/config.hpp>
22
#include <boost/asio/detail/pop_options.hpp>
24
#include <boost/asio/basic_io_object.hpp>
25
#include <boost/asio/error.hpp>
26
#include <boost/asio/detail/throw_error.hpp>
32
/// Provides Windows handle functionality.
34
* The windows::basic_handle class template provides the ability to wrap a
38
* @e Distinct @e objects: Safe.@n
39
* @e Shared @e objects: Unsafe.
41
template <typename HandleService>
43
: public basic_io_object<HandleService>
46
/// The native representation of a handle.
47
typedef typename HandleService::native_type native_type;
49
/// A basic_handle is always the lowest layer.
50
typedef basic_handle<HandleService> lowest_layer_type;
52
/// Construct a basic_handle without opening it.
54
* This constructor creates a handle without opening it.
56
* @param io_service The io_service object that the handle will use to
57
* dispatch handlers for any asynchronous operations performed on the handle.
59
explicit basic_handle(boost::asio::io_service& io_service)
60
: basic_io_object<HandleService>(io_service)
64
/// Construct a basic_handle on an existing native handle.
66
* This constructor creates a handle object to hold an existing native handle.
68
* @param io_service The io_service object that the handle will use to
69
* dispatch handlers for any asynchronous operations performed on the handle.
71
* @param native_handle A native handle.
73
* @throws boost::system::system_error Thrown on failure.
75
basic_handle(boost::asio::io_service& io_service,
76
const native_type& native_handle)
77
: basic_io_object<HandleService>(io_service)
79
boost::system::error_code ec;
80
this->service.assign(this->implementation, native_handle, ec);
81
boost::asio::detail::throw_error(ec);
84
/// Get a reference to the lowest layer.
86
* This function returns a reference to the lowest layer in a stack of
87
* layers. Since a basic_handle cannot contain any further layers, it simply
88
* returns a reference to itself.
90
* @return A reference to the lowest layer in the stack of layers. Ownership
91
* is not transferred to the caller.
93
lowest_layer_type& lowest_layer()
98
/// Get a const reference to the lowest layer.
100
* This function returns a const reference to the lowest layer in a stack of
101
* layers. Since a basic_handle cannot contain any further layers, it simply
102
* returns a reference to itself.
104
* @return A const reference to the lowest layer in the stack of layers.
105
* Ownership is not transferred to the caller.
107
const lowest_layer_type& lowest_layer() const
112
/// Assign an existing native handle to the handle.
114
* This function opens the handle to hold an existing native handle.
116
* @param native_handle A native handle.
118
* @throws boost::system::system_error Thrown on failure.
120
void assign(const native_type& native_handle)
122
boost::system::error_code ec;
123
this->service.assign(this->implementation, native_handle, ec);
124
boost::asio::detail::throw_error(ec);
127
/// Assign an existing native handle to the handle.
129
* This function opens the handle to hold an existing native handle.
131
* @param native_handle A native handle.
133
* @param ec Set to indicate what error occurred, if any.
135
boost::system::error_code assign(const native_type& native_handle,
136
boost::system::error_code& ec)
138
return this->service.assign(this->implementation, native_handle, ec);
141
/// Determine whether the handle is open.
144
return this->service.is_open(this->implementation);
147
/// Close the handle.
149
* This function is used to close the handle. Any asynchronous read or write
150
* operations will be cancelled immediately, and will complete with the
151
* boost::asio::error::operation_aborted error.
153
* @throws boost::system::system_error Thrown on failure.
157
boost::system::error_code ec;
158
this->service.close(this->implementation, ec);
159
boost::asio::detail::throw_error(ec);
162
/// Close the handle.
164
* This function is used to close the handle. Any asynchronous read or write
165
* operations will be cancelled immediately, and will complete with the
166
* boost::asio::error::operation_aborted error.
168
* @param ec Set to indicate what error occurred, if any.
170
boost::system::error_code close(boost::system::error_code& ec)
172
return this->service.close(this->implementation, ec);
175
/// Get the native handle representation.
177
* This function may be used to obtain the underlying representation of the
178
* handle. This is intended to allow access to native handle functionality
179
* that is not otherwise provided.
183
return this->service.native(this->implementation);
186
/// Cancel all asynchronous operations associated with the handle.
188
* This function causes all outstanding asynchronous read or write operations
189
* to finish immediately, and the handlers for cancelled operations will be
190
* passed the boost::asio::error::operation_aborted error.
192
* @throws boost::system::system_error Thrown on failure.
196
boost::system::error_code ec;
197
this->service.cancel(this->implementation, ec);
198
boost::asio::detail::throw_error(ec);
201
/// Cancel all asynchronous operations associated with the handle.
203
* This function causes all outstanding asynchronous read or write operations
204
* to finish immediately, and the handlers for cancelled operations will be
205
* passed the boost::asio::error::operation_aborted error.
207
* @param ec Set to indicate what error occurred, if any.
209
boost::system::error_code cancel(boost::system::error_code& ec)
211
return this->service.cancel(this->implementation, ec);
215
/// Protected destructor to prevent deletion through this type.
221
} // namespace windows
225
#include <boost/asio/detail/pop_options.hpp>
227
#endif // BOOST_ASIO_WINDOWS_BASIC_HANDLE_HPP