~cmiller/ubuntu/quantal/deluge/fix-parameter-move-storage

« back to all changes in this revision

Viewing changes to libtorrent/include/asio/windows/basic_handle.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Cristian Greco
  • Date: 2009-11-13 02:39:45 UTC
  • mfrom: (4.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091113023945-te1bybo2912ejzuc
Tags: 1.2.0~rc3-4
* debian/control: bump build-dep on python-setuptools to (>= 0.6c9).
* debian/patches:
  - 25_r5921_fastresume_files.patch
    new, should fix problems with fresh configs;
  - 30_r5931_ipc_lockfile.patch:
    new, should fix an issue where Deluge will fail to start if there is a
    stale ipc lockfile. (Closes: #555849)

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 ASIO_WINDOWS_BASIC_HANDLE_HPP
12
 
#define 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 "asio/detail/push_options.hpp"
19
 
 
20
 
#include "asio/detail/push_options.hpp"
21
 
#include <boost/config.hpp>
22
 
#include "asio/detail/pop_options.hpp"
23
 
 
24
 
#include "asio/basic_io_object.hpp"
25
 
#include "asio/error.hpp"
26
 
#include "asio/detail/throw_error.hpp"
27
 
 
28
 
namespace asio {
29
 
namespace windows {
30
 
 
31
 
/// Provides Windows handle functionality.
32
 
/**
33
 
 * The windows::basic_handle class template provides the ability to wrap a
34
 
 * Windows handle.
35
 
 *
36
 
 * @par Thread Safety
37
 
 * @e Distinct @e objects: Safe.@n
38
 
 * @e Shared @e objects: Unsafe.
39
 
 */
40
 
template <typename HandleService>
41
 
class basic_handle
42
 
  : public basic_io_object<HandleService>
43
 
{
44
 
public:
45
 
  /// The native representation of a handle.
46
 
  typedef typename HandleService::native_type native_type;
47
 
 
48
 
  /// A basic_handle is always the lowest layer.
49
 
  typedef basic_handle<HandleService> lowest_layer_type;
50
 
 
51
 
  /// Construct a basic_handle without opening it.
52
 
  /**
53
 
   * This constructor creates a handle without opening it.
54
 
   *
55
 
   * @param io_service The io_service object that the handle will use to
56
 
   * dispatch handlers for any asynchronous operations performed on the handle.
57
 
   */
58
 
  explicit basic_handle(asio::io_service& io_service)
59
 
    : basic_io_object<HandleService>(io_service)
60
 
  {
61
 
  }
62
 
 
63
 
  /// Construct a basic_handle on an existing native handle.
64
 
  /**
65
 
   * This constructor creates a handle object to hold an existing native handle.
66
 
   *
67
 
   * @param io_service The io_service object that the handle will use to
68
 
   * dispatch handlers for any asynchronous operations performed on the handle.
69
 
   *
70
 
   * @param native_handle A native handle.
71
 
   *
72
 
   * @throws asio::system_error Thrown on failure.
73
 
   */
74
 
  basic_handle(asio::io_service& io_service,
75
 
      const native_type& native_handle)
76
 
    : basic_io_object<HandleService>(io_service)
77
 
  {
78
 
    asio::error_code ec;
79
 
    this->service.assign(this->implementation, native_handle, ec);
80
 
    asio::detail::throw_error(ec);
81
 
  }
82
 
 
83
 
  /// Get a reference to the lowest layer.
84
 
  /**
85
 
   * This function returns a reference to the lowest layer in a stack of
86
 
   * layers. Since a basic_handle cannot contain any further layers, it simply
87
 
   * returns a reference to itself.
88
 
   *
89
 
   * @return A reference to the lowest layer in the stack of layers. Ownership
90
 
   * is not transferred to the caller.
91
 
   */
92
 
  lowest_layer_type& lowest_layer()
93
 
  {
94
 
    return *this;
95
 
  }
96
 
 
97
 
  /// Get a const reference to the lowest layer.
98
 
  /**
99
 
   * This function returns a const reference to the lowest layer in a stack of
100
 
   * layers. Since a basic_handle cannot contain any further layers, it simply
101
 
   * returns a reference to itself.
102
 
   *
103
 
   * @return A const reference to the lowest layer in the stack of layers.
104
 
   * Ownership is not transferred to the caller.
105
 
   */
106
 
  const lowest_layer_type& lowest_layer() const
107
 
  {
108
 
    return *this;
109
 
  }
110
 
 
111
 
  /// Assign an existing native handle to the handle.
112
 
  /*
113
 
   * This function opens the handle to hold an existing native handle.
114
 
   *
115
 
   * @param native_handle A native handle.
116
 
   *
117
 
   * @throws asio::system_error Thrown on failure.
118
 
   */
119
 
  void assign(const native_type& native_handle)
120
 
  {
121
 
    asio::error_code ec;
122
 
    this->service.assign(this->implementation, native_handle, ec);
123
 
    asio::detail::throw_error(ec);
124
 
  }
125
 
 
126
 
  /// Assign an existing native handle to the handle.
127
 
  /*
128
 
   * This function opens the handle to hold an existing native handle.
129
 
   *
130
 
   * @param native_handle A native handle.
131
 
   *
132
 
   * @param ec Set to indicate what error occurred, if any.
133
 
   */
134
 
  asio::error_code assign(const native_type& native_handle,
135
 
      asio::error_code& ec)
136
 
  {
137
 
    return this->service.assign(this->implementation, native_handle, ec);
138
 
  }
139
 
 
140
 
  /// Determine whether the handle is open.
141
 
  bool is_open() const
142
 
  {
143
 
    return this->service.is_open(this->implementation);
144
 
  }
145
 
 
146
 
  /// Close the handle.
147
 
  /**
148
 
   * This function is used to close the handle. Any asynchronous read or write
149
 
   * operations will be cancelled immediately, and will complete with the
150
 
   * asio::error::operation_aborted error.
151
 
   *
152
 
   * @throws asio::system_error Thrown on failure.
153
 
   */
154
 
  void close()
155
 
  {
156
 
    asio::error_code ec;
157
 
    this->service.close(this->implementation, ec);
158
 
    asio::detail::throw_error(ec);
159
 
  }
160
 
 
161
 
  /// Close the handle.
162
 
  /**
163
 
   * This function is used to close the handle. Any asynchronous read or write
164
 
   * operations will be cancelled immediately, and will complete with the
165
 
   * asio::error::operation_aborted error.
166
 
   *
167
 
   * @param ec Set to indicate what error occurred, if any.
168
 
   */
169
 
  asio::error_code close(asio::error_code& ec)
170
 
  {
171
 
    return this->service.close(this->implementation, ec);
172
 
  }
173
 
 
174
 
  /// Get the native handle representation.
175
 
  /**
176
 
   * This function may be used to obtain the underlying representation of the
177
 
   * handle. This is intended to allow access to native handle functionality
178
 
   * that is not otherwise provided.
179
 
   */
180
 
  native_type native()
181
 
  {
182
 
    return this->service.native(this->implementation);
183
 
  }
184
 
 
185
 
  /// Cancel all asynchronous operations associated with the handle.
186
 
  /**
187
 
   * This function causes all outstanding asynchronous read or write operations
188
 
   * to finish immediately, and the handlers for cancelled operations will be
189
 
   * passed the asio::error::operation_aborted error.
190
 
   *
191
 
   * @throws asio::system_error Thrown on failure.
192
 
   */
193
 
  void cancel()
194
 
  {
195
 
    asio::error_code ec;
196
 
    this->service.cancel(this->implementation, ec);
197
 
    asio::detail::throw_error(ec);
198
 
  }
199
 
 
200
 
  /// Cancel all asynchronous operations associated with the handle.
201
 
  /**
202
 
   * This function causes all outstanding asynchronous read or write operations
203
 
   * to finish immediately, and the handlers for cancelled operations will be
204
 
   * passed the asio::error::operation_aborted error.
205
 
   *
206
 
   * @param ec Set to indicate what error occurred, if any.
207
 
   */
208
 
  asio::error_code cancel(asio::error_code& ec)
209
 
  {
210
 
    return this->service.cancel(this->implementation, ec);
211
 
  }
212
 
 
213
 
protected:
214
 
  /// Protected destructor to prevent deletion through this type.
215
 
  ~basic_handle()
216
 
  {
217
 
  }
218
 
};
219
 
 
220
 
} // namespace windows
221
 
} // namespace asio
222
 
 
223
 
#include "asio/detail/pop_options.hpp"
224
 
 
225
 
#endif // ASIO_WINDOWS_BASIC_HANDLE_HPP