~twpol/dcplusplus/trunk

« back to all changes in this revision

Viewing changes to boost/boost/asio/windows/basic_handle.hpp

  • Committer: James Ross
  • Date: 2010-07-05 00:03:18 UTC
  • mfrom: (1524.1.650 dcplusplus)
  • Revision ID: silver@warwickcompsoc.co.uk-20100705000318-awwqm8ocpp5m47yz
Merged to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// basic_handle.hpp
3
 
// ~~~~~~~~~~~~~~~~
4
 
//
5
 
// Copyright (c) 2003-2008 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
 
 
11
 
#ifndef BOOST_ASIO_WINDOWS_BASIC_HANDLE_HPP
12
 
#define BOOST_ASIO_WINDOWS_BASIC_HANDLE_HPP
13
 
 
14
 
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15
 
# pragma once
16
 
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
 
 
18
 
#include <boost/asio/detail/push_options.hpp>
19
 
 
20
 
#include <boost/asio/detail/push_options.hpp>
21
 
#include <boost/config.hpp>
22
 
#include <boost/asio/detail/pop_options.hpp>
23
 
 
24
 
#include <boost/asio/basic_io_object.hpp>
25
 
#include <boost/asio/error.hpp>
26
 
#include <boost/asio/detail/throw_error.hpp>
27
 
 
28
 
namespace boost {
29
 
namespace asio {
30
 
namespace windows {
31
 
 
32
 
/// Provides Windows handle functionality.
33
 
/**
34
 
 * The windows::basic_handle class template provides the ability to wrap a
35
 
 * Windows handle.
36
 
 *
37
 
 * @par Thread Safety
38
 
 * @e Distinct @e objects: Safe.@n
39
 
 * @e Shared @e objects: Unsafe.
40
 
 */
41
 
template <typename HandleService>
42
 
class basic_handle
43
 
  : public basic_io_object<HandleService>
44
 
{
45
 
public:
46
 
  /// The native representation of a handle.
47
 
  typedef typename HandleService::native_type native_type;
48
 
 
49
 
  /// A basic_handle is always the lowest layer.
50
 
  typedef basic_handle<HandleService> lowest_layer_type;
51
 
 
52
 
  /// Construct a basic_handle without opening it.
53
 
  /**
54
 
   * This constructor creates a handle without opening it.
55
 
   *
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.
58
 
   */
59
 
  explicit basic_handle(boost::asio::io_service& io_service)
60
 
    : basic_io_object<HandleService>(io_service)
61
 
  {
62
 
  }
63
 
 
64
 
  /// Construct a basic_handle on an existing native handle.
65
 
  /**
66
 
   * This constructor creates a handle object to hold an existing native handle.
67
 
   *
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.
70
 
   *
71
 
   * @param native_handle A native handle.
72
 
   *
73
 
   * @throws boost::system::system_error Thrown on failure.
74
 
   */
75
 
  basic_handle(boost::asio::io_service& io_service,
76
 
      const native_type& native_handle)
77
 
    : basic_io_object<HandleService>(io_service)
78
 
  {
79
 
    boost::system::error_code ec;
80
 
    this->service.assign(this->implementation, native_handle, ec);
81
 
    boost::asio::detail::throw_error(ec);
82
 
  }
83
 
 
84
 
  /// Get a reference to the lowest layer.
85
 
  /**
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.
89
 
   *
90
 
   * @return A reference to the lowest layer in the stack of layers. Ownership
91
 
   * is not transferred to the caller.
92
 
   */
93
 
  lowest_layer_type& lowest_layer()
94
 
  {
95
 
    return *this;
96
 
  }
97
 
 
98
 
  /// Get a const reference to the lowest layer.
99
 
  /**
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.
103
 
   *
104
 
   * @return A const reference to the lowest layer in the stack of layers.
105
 
   * Ownership is not transferred to the caller.
106
 
   */
107
 
  const lowest_layer_type& lowest_layer() const
108
 
  {
109
 
    return *this;
110
 
  }
111
 
 
112
 
  /// Assign an existing native handle to the handle.
113
 
  /*
114
 
   * This function opens the handle to hold an existing native handle.
115
 
   *
116
 
   * @param native_handle A native handle.
117
 
   *
118
 
   * @throws boost::system::system_error Thrown on failure.
119
 
   */
120
 
  void assign(const native_type& native_handle)
121
 
  {
122
 
    boost::system::error_code ec;
123
 
    this->service.assign(this->implementation, native_handle, ec);
124
 
    boost::asio::detail::throw_error(ec);
125
 
  }
126
 
 
127
 
  /// Assign an existing native handle to the handle.
128
 
  /*
129
 
   * This function opens the handle to hold an existing native handle.
130
 
   *
131
 
   * @param native_handle A native handle.
132
 
   *
133
 
   * @param ec Set to indicate what error occurred, if any.
134
 
   */
135
 
  boost::system::error_code assign(const native_type& native_handle,
136
 
      boost::system::error_code& ec)
137
 
  {
138
 
    return this->service.assign(this->implementation, native_handle, ec);
139
 
  }
140
 
 
141
 
  /// Determine whether the handle is open.
142
 
  bool is_open() const
143
 
  {
144
 
    return this->service.is_open(this->implementation);
145
 
  }
146
 
 
147
 
  /// Close the handle.
148
 
  /**
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.
152
 
   *
153
 
   * @throws boost::system::system_error Thrown on failure.
154
 
   */
155
 
  void close()
156
 
  {
157
 
    boost::system::error_code ec;
158
 
    this->service.close(this->implementation, ec);
159
 
    boost::asio::detail::throw_error(ec);
160
 
  }
161
 
 
162
 
  /// Close the handle.
163
 
  /**
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.
167
 
   *
168
 
   * @param ec Set to indicate what error occurred, if any.
169
 
   */
170
 
  boost::system::error_code close(boost::system::error_code& ec)
171
 
  {
172
 
    return this->service.close(this->implementation, ec);
173
 
  }
174
 
 
175
 
  /// Get the native handle representation.
176
 
  /**
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.
180
 
   */
181
 
  native_type native()
182
 
  {
183
 
    return this->service.native(this->implementation);
184
 
  }
185
 
 
186
 
  /// Cancel all asynchronous operations associated with the handle.
187
 
  /**
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.
191
 
   *
192
 
   * @throws boost::system::system_error Thrown on failure.
193
 
   */
194
 
  void cancel()
195
 
  {
196
 
    boost::system::error_code ec;
197
 
    this->service.cancel(this->implementation, ec);
198
 
    boost::asio::detail::throw_error(ec);
199
 
  }
200
 
 
201
 
  /// Cancel all asynchronous operations associated with the handle.
202
 
  /**
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.
206
 
   *
207
 
   * @param ec Set to indicate what error occurred, if any.
208
 
   */
209
 
  boost::system::error_code cancel(boost::system::error_code& ec)
210
 
  {
211
 
    return this->service.cancel(this->implementation, ec);
212
 
  }
213
 
 
214
 
protected:
215
 
  /// Protected destructor to prevent deletion through this type.
216
 
  ~basic_handle()
217
 
  {
218
 
  }
219
 
};
220
 
 
221
 
} // namespace windows
222
 
} // namespace asio
223
 
} // namespace boost
224
 
 
225
 
#include <boost/asio/detail/pop_options.hpp>
226
 
 
227
 
#endif // BOOST_ASIO_WINDOWS_BASIC_HANDLE_HPP
 
1
//
 
2
// basic_handle.hpp
 
3
// ~~~~~~~~~~~~~~~~
 
4
//
 
5
// Copyright (c) 2003-2008 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
 
 
11
#ifndef BOOST_ASIO_WINDOWS_BASIC_HANDLE_HPP
 
12
#define BOOST_ASIO_WINDOWS_BASIC_HANDLE_HPP
 
13
 
 
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
 
15
# pragma once
 
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
 
17
 
 
18
#include <boost/asio/detail/push_options.hpp>
 
19
 
 
20
#include <boost/asio/detail/push_options.hpp>
 
21
#include <boost/config.hpp>
 
22
#include <boost/asio/detail/pop_options.hpp>
 
23
 
 
24
#include <boost/asio/basic_io_object.hpp>
 
25
#include <boost/asio/error.hpp>
 
26
#include <boost/asio/detail/throw_error.hpp>
 
27
 
 
28
namespace boost {
 
29
namespace asio {
 
30
namespace windows {
 
31
 
 
32
/// Provides Windows handle functionality.
 
33
/**
 
34
 * The windows::basic_handle class template provides the ability to wrap a
 
35
 * Windows handle.
 
36
 *
 
37
 * @par Thread Safety
 
38
 * @e Distinct @e objects: Safe.@n
 
39
 * @e Shared @e objects: Unsafe.
 
40
 */
 
41
template <typename HandleService>
 
42
class basic_handle
 
43
  : public basic_io_object<HandleService>
 
44
{
 
45
public:
 
46
  /// The native representation of a handle.
 
47
  typedef typename HandleService::native_type native_type;
 
48
 
 
49
  /// A basic_handle is always the lowest layer.
 
50
  typedef basic_handle<HandleService> lowest_layer_type;
 
51
 
 
52
  /// Construct a basic_handle without opening it.
 
53
  /**
 
54
   * This constructor creates a handle without opening it.
 
55
   *
 
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.
 
58
   */
 
59
  explicit basic_handle(boost::asio::io_service& io_service)
 
60
    : basic_io_object<HandleService>(io_service)
 
61
  {
 
62
  }
 
63
 
 
64
  /// Construct a basic_handle on an existing native handle.
 
65
  /**
 
66
   * This constructor creates a handle object to hold an existing native handle.
 
67
   *
 
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.
 
70
   *
 
71
   * @param native_handle A native handle.
 
72
   *
 
73
   * @throws boost::system::system_error Thrown on failure.
 
74
   */
 
75
  basic_handle(boost::asio::io_service& io_service,
 
76
      const native_type& native_handle)
 
77
    : basic_io_object<HandleService>(io_service)
 
78
  {
 
79
    boost::system::error_code ec;
 
80
    this->service.assign(this->implementation, native_handle, ec);
 
81
    boost::asio::detail::throw_error(ec);
 
82
  }
 
83
 
 
84
  /// Get a reference to the lowest layer.
 
85
  /**
 
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.
 
89
   *
 
90
   * @return A reference to the lowest layer in the stack of layers. Ownership
 
91
   * is not transferred to the caller.
 
92
   */
 
93
  lowest_layer_type& lowest_layer()
 
94
  {
 
95
    return *this;
 
96
  }
 
97
 
 
98
  /// Get a const reference to the lowest layer.
 
99
  /**
 
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.
 
103
   *
 
104
   * @return A const reference to the lowest layer in the stack of layers.
 
105
   * Ownership is not transferred to the caller.
 
106
   */
 
107
  const lowest_layer_type& lowest_layer() const
 
108
  {
 
109
    return *this;
 
110
  }
 
111
 
 
112
  /// Assign an existing native handle to the handle.
 
113
  /*
 
114
   * This function opens the handle to hold an existing native handle.
 
115
   *
 
116
   * @param native_handle A native handle.
 
117
   *
 
118
   * @throws boost::system::system_error Thrown on failure.
 
119
   */
 
120
  void assign(const native_type& native_handle)
 
121
  {
 
122
    boost::system::error_code ec;
 
123
    this->service.assign(this->implementation, native_handle, ec);
 
124
    boost::asio::detail::throw_error(ec);
 
125
  }
 
126
 
 
127
  /// Assign an existing native handle to the handle.
 
128
  /*
 
129
   * This function opens the handle to hold an existing native handle.
 
130
   *
 
131
   * @param native_handle A native handle.
 
132
   *
 
133
   * @param ec Set to indicate what error occurred, if any.
 
134
   */
 
135
  boost::system::error_code assign(const native_type& native_handle,
 
136
      boost::system::error_code& ec)
 
137
  {
 
138
    return this->service.assign(this->implementation, native_handle, ec);
 
139
  }
 
140
 
 
141
  /// Determine whether the handle is open.
 
142
  bool is_open() const
 
143
  {
 
144
    return this->service.is_open(this->implementation);
 
145
  }
 
146
 
 
147
  /// Close the handle.
 
148
  /**
 
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.
 
152
   *
 
153
   * @throws boost::system::system_error Thrown on failure.
 
154
   */
 
155
  void close()
 
156
  {
 
157
    boost::system::error_code ec;
 
158
    this->service.close(this->implementation, ec);
 
159
    boost::asio::detail::throw_error(ec);
 
160
  }
 
161
 
 
162
  /// Close the handle.
 
163
  /**
 
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.
 
167
   *
 
168
   * @param ec Set to indicate what error occurred, if any.
 
169
   */
 
170
  boost::system::error_code close(boost::system::error_code& ec)
 
171
  {
 
172
    return this->service.close(this->implementation, ec);
 
173
  }
 
174
 
 
175
  /// Get the native handle representation.
 
176
  /**
 
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.
 
180
   */
 
181
  native_type native()
 
182
  {
 
183
    return this->service.native(this->implementation);
 
184
  }
 
185
 
 
186
  /// Cancel all asynchronous operations associated with the handle.
 
187
  /**
 
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.
 
191
   *
 
192
   * @throws boost::system::system_error Thrown on failure.
 
193
   */
 
194
  void cancel()
 
195
  {
 
196
    boost::system::error_code ec;
 
197
    this->service.cancel(this->implementation, ec);
 
198
    boost::asio::detail::throw_error(ec);
 
199
  }
 
200
 
 
201
  /// Cancel all asynchronous operations associated with the handle.
 
202
  /**
 
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.
 
206
   *
 
207
   * @param ec Set to indicate what error occurred, if any.
 
208
   */
 
209
  boost::system::error_code cancel(boost::system::error_code& ec)
 
210
  {
 
211
    return this->service.cancel(this->implementation, ec);
 
212
  }
 
213
 
 
214
protected:
 
215
  /// Protected destructor to prevent deletion through this type.
 
216
  ~basic_handle()
 
217
  {
 
218
  }
 
219
};
 
220
 
 
221
} // namespace windows
 
222
} // namespace asio
 
223
} // namespace boost
 
224
 
 
225
#include <boost/asio/detail/pop_options.hpp>
 
226
 
 
227
#endif // BOOST_ASIO_WINDOWS_BASIC_HANDLE_HPP