~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to include/libtorrent/asio/read.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Cristian Greco
  • Date: 2008-07-02 10:46:21 UTC
  • Revision ID: james.westby@ubuntu.com-20080702104621-jzx3pfke9lkcxfxn
Tags: upstream-0.13.1
ImportĀ upstreamĀ versionĀ 0.13.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// read.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_READ_HPP
 
12
#define ASIO_READ_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 <cstddef>
 
22
#include <boost/config.hpp>
 
23
#include "asio/detail/pop_options.hpp"
 
24
 
 
25
#include "asio/basic_streambuf.hpp"
 
26
#include "asio/error.hpp"
 
27
 
 
28
namespace asio {
 
29
 
 
30
/**
 
31
 * @defgroup read asio::read
 
32
 */
 
33
/*@{*/
 
34
 
 
35
/// Attempt to read a certain amount of data from a stream before returning.
 
36
/**
 
37
 * This function is used to read a certain number of bytes of data from a
 
38
 * stream. The call will block until one of the following conditions is true:
 
39
 *
 
40
 * @li The supplied buffers are full. That is, the bytes transferred is equal to
 
41
 * the sum of the buffer sizes.
 
42
 *
 
43
 * @li An error occurred.
 
44
 *
 
45
 * This operation is implemented in terms of one or more calls to the stream's
 
46
 * read_some function.
 
47
 *
 
48
 * @param s The stream from which the data is to be read. The type must support
 
49
 * the SyncReadStream concept.
 
50
 *
 
51
 * @param buffers One or more buffers into which the data will be read. The sum
 
52
 * of the buffer sizes indicates the maximum number of bytes to read from the
 
53
 * stream.
 
54
 *
 
55
 * @returns The number of bytes transferred.
 
56
 *
 
57
 * @throws asio::system_error Thrown on failure.
 
58
 *
 
59
 * @par Example
 
60
 * To read into a single data buffer use the @ref buffer function as follows:
 
61
 * @code asio::read(s, asio::buffer(data, size)); @endcode
 
62
 * See the @ref buffer documentation for information on reading into multiple
 
63
 * buffers in one go, and how to use it with arrays, boost::array or
 
64
 * std::vector.
 
65
 *
 
66
 * @note This overload is equivalent to calling:
 
67
 * @code asio::read(
 
68
 *     s, buffers,
 
69
 *     asio::transfer_all()); @endcode
 
70
 */
 
71
template <typename SyncReadStream, typename MutableBufferSequence>
 
72
std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers);
 
73
 
 
74
/// Attempt to read a certain amount of data from a stream before returning.
 
75
/**
 
76
 * This function is used to read a certain number of bytes of data from a
 
77
 * stream. The call will block until one of the following conditions is true:
 
78
 *
 
79
 * @li The supplied buffers are full. That is, the bytes transferred is equal to
 
80
 * the sum of the buffer sizes.
 
81
 *
 
82
 * @li The completion_condition function object returns true.
 
83
 *
 
84
 * This operation is implemented in terms of one or more calls to the stream's
 
85
 * read_some function.
 
86
 *
 
87
 * @param s The stream from which the data is to be read. The type must support
 
88
 * the SyncReadStream concept.
 
89
 *
 
90
 * @param buffers One or more buffers into which the data will be read. The sum
 
91
 * of the buffer sizes indicates the maximum number of bytes to read from the
 
92
 * stream.
 
93
 *
 
94
 * @param completion_condition The function object to be called to determine
 
95
 * whether the read operation is complete. The signature of the function object
 
96
 * must be:
 
97
 * @code bool completion_condition(
 
98
 *   const asio::error_code& error, // Result of latest read_some
 
99
 *                                           // operation.
 
100
 *
 
101
 *   std::size_t bytes_transferred           // Number of bytes transferred
 
102
 *                                           // so far.
 
103
 * ); @endcode
 
104
 * A return value of true indicates that the read operation is complete. False
 
105
 * indicates that further calls to the stream's read_some function are required.
 
106
 *
 
107
 * @returns The number of bytes transferred.
 
108
 *
 
109
 * @throws asio::system_error Thrown on failure.
 
110
 *
 
111
 * @par Example
 
112
 * To read into a single data buffer use the @ref buffer function as follows:
 
113
 * @code asio::read(s, asio::buffer(data, size),
 
114
 *     asio::transfer_at_least(32)); @endcode
 
115
 * See the @ref buffer documentation for information on reading into multiple
 
116
 * buffers in one go, and how to use it with arrays, boost::array or
 
117
 * std::vector.
 
118
 */
 
119
template <typename SyncReadStream, typename MutableBufferSequence,
 
120
  typename CompletionCondition>
 
121
std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
 
122
    CompletionCondition completion_condition);
 
123
 
 
124
/// Attempt to read a certain amount of data from a stream before returning.
 
125
/**
 
126
 * This function is used to read a certain number of bytes of data from a
 
127
 * stream. The call will block until one of the following conditions is true:
 
128
 *
 
129
 * @li The supplied buffers are full. That is, the bytes transferred is equal to
 
130
 * the sum of the buffer sizes.
 
131
 *
 
132
 * @li The completion_condition function object returns true.
 
133
 *
 
134
 * This operation is implemented in terms of one or more calls to the stream's
 
135
 * read_some function.
 
136
 *
 
137
 * @param s The stream from which the data is to be read. The type must support
 
138
 * the SyncReadStream concept.
 
139
 *
 
140
 * @param buffers One or more buffers into which the data will be read. The sum
 
141
 * of the buffer sizes indicates the maximum number of bytes to read from the
 
142
 * stream.
 
143
 *
 
144
 * @param completion_condition The function object to be called to determine
 
145
 * whether the read operation is complete. The signature of the function object
 
146
 * must be:
 
147
 * @code bool completion_condition(
 
148
 *   const asio::error_code& error, // Result of latest read_some
 
149
 *                                           // operation.
 
150
 *
 
151
 *   std::size_t bytes_transferred           // Number of bytes transferred
 
152
 *                                           // so far.
 
153
 * ); @endcode
 
154
 * A return value of true indicates that the read operation is complete. False
 
155
 * indicates that further calls to the stream's read_some function are required.
 
156
 *
 
157
 * @param ec Set to indicate what error occurred, if any.
 
158
 *
 
159
 * @returns The number of bytes read. If an error occurs, returns the total
 
160
 * number of bytes successfully transferred prior to the error.
 
161
 */
 
162
template <typename SyncReadStream, typename MutableBufferSequence,
 
163
    typename CompletionCondition>
 
164
std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
 
165
    CompletionCondition completion_condition, asio::error_code& ec);
 
166
 
 
167
/// Attempt to read a certain amount of data from a stream before returning.
 
168
/**
 
169
 * This function is used to read a certain number of bytes of data from a
 
170
 * stream. The call will block until one of the following conditions is true:
 
171
 *
 
172
 * @li An error occurred.
 
173
 *
 
174
 * This operation is implemented in terms of one or more calls to the stream's
 
175
 * read_some function.
 
176
 *
 
177
 * @param s The stream from which the data is to be read. The type must support
 
178
 * the SyncReadStream concept.
 
179
 *
 
180
 * @param b The basic_streambuf object into which the data will be read.
 
181
 *
 
182
 * @returns The number of bytes transferred.
 
183
 *
 
184
 * @throws asio::system_error Thrown on failure.
 
185
 *
 
186
 * @note This overload is equivalent to calling:
 
187
 * @code asio::read(
 
188
 *     s, b,
 
189
 *     asio::transfer_all()); @endcode
 
190
 */
 
191
template <typename SyncReadStream, typename Allocator>
 
192
std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b);
 
193
 
 
194
/// Attempt to read a certain amount of data from a stream before returning.
 
195
/**
 
196
 * This function is used to read a certain number of bytes of data from a
 
197
 * stream. The call will block until one of the following conditions is true:
 
198
 *
 
199
 * @li The completion_condition function object returns true.
 
200
 *
 
201
 * This operation is implemented in terms of one or more calls to the stream's
 
202
 * read_some function.
 
203
 *
 
204
 * @param s The stream from which the data is to be read. The type must support
 
205
 * the SyncReadStream concept.
 
206
 *
 
207
 * @param b The basic_streambuf object into which the data will be read.
 
208
 *
 
209
 * @param completion_condition The function object to be called to determine
 
210
 * whether the read operation is complete. The signature of the function object
 
211
 * must be:
 
212
 * @code bool completion_condition(
 
213
 *   const asio::error_code& error, // Result of latest read_some
 
214
 *                                           // operation.
 
215
 *
 
216
 *   std::size_t bytes_transferred           // Number of bytes transferred
 
217
 *                                           // so far.
 
218
 * ); @endcode
 
219
 * A return value of true indicates that the read operation is complete. False
 
220
 * indicates that further calls to the stream's read_some function are required.
 
221
 *
 
222
 * @returns The number of bytes transferred.
 
223
 *
 
224
 * @throws asio::system_error Thrown on failure.
 
225
 */
 
226
template <typename SyncReadStream, typename Allocator,
 
227
    typename CompletionCondition>
 
228
std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
 
229
    CompletionCondition completion_condition);
 
230
 
 
231
/// Attempt to read a certain amount of data from a stream before returning.
 
232
/**
 
233
 * This function is used to read a certain number of bytes of data from a
 
234
 * stream. The call will block until one of the following conditions is true:
 
235
 *
 
236
 * @li The completion_condition function object returns true.
 
237
 *
 
238
 * This operation is implemented in terms of one or more calls to the stream's
 
239
 * read_some function.
 
240
 *
 
241
 * @param s The stream from which the data is to be read. The type must support
 
242
 * the SyncReadStream concept.
 
243
 *
 
244
 * @param b The basic_streambuf object into which the data will be read.
 
245
 *
 
246
 * @param completion_condition The function object to be called to determine
 
247
 * whether the read operation is complete. The signature of the function object
 
248
 * must be:
 
249
 * @code bool completion_condition(
 
250
 *   const asio::error_code& error, // Result of latest read_some
 
251
 *                                           // operation.
 
252
 *
 
253
 *   std::size_t bytes_transferred           // Number of bytes transferred
 
254
 *                                           // so far.
 
255
 * ); @endcode
 
256
 * A return value of true indicates that the read operation is complete. False
 
257
 * indicates that further calls to the stream's read_some function are required.
 
258
 *
 
259
 * @param ec Set to indicate what error occurred, if any.
 
260
 *
 
261
 * @returns The number of bytes read. If an error occurs, returns the total
 
262
 * number of bytes successfully transferred prior to the error.
 
263
 */
 
264
template <typename SyncReadStream, typename Allocator,
 
265
    typename CompletionCondition>
 
266
std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
 
267
    CompletionCondition completion_condition, asio::error_code& ec);
 
268
 
 
269
/*@}*/
 
270
/**
 
271
 * @defgroup async_read asio::async_read
 
272
 */
 
273
/*@{*/
 
274
 
 
275
/// Start an asynchronous operation to read a certain amount of data from a
 
276
/// stream.
 
277
/**
 
278
 * This function is used to asynchronously read a certain number of bytes of
 
279
 * data from a stream. The function call always returns immediately. The
 
280
 * asynchronous operation will continue until one of the following conditions is
 
281
 * true:
 
282
 *
 
283
 * @li The supplied buffers are full. That is, the bytes transferred is equal to
 
284
 * the sum of the buffer sizes.
 
285
 *
 
286
 * @li An error occurred.
 
287
 *
 
288
 * This operation is implemented in terms of one or more calls to the stream's
 
289
 * async_read_some function.
 
290
 *
 
291
 * @param s The stream from which the data is to be read. The type must support
 
292
 * the AsyncReadStream concept.
 
293
 *
 
294
 * @param buffers One or more buffers into which the data will be read. The sum
 
295
 * of the buffer sizes indicates the maximum number of bytes to read from the
 
296
 * stream. Although the buffers object may be copied as necessary, ownership of
 
297
 * the underlying memory blocks is retained by the caller, which must guarantee
 
298
 * that they remain valid until the handler is called.
 
299
 *
 
300
 * @param handler The handler to be called when the read operation completes.
 
301
 * Copies will be made of the handler as required. The function signature of the
 
302
 * handler must be:
 
303
 * @code void handler(
 
304
 *   const asio::error_code& error, // Result of operation.
 
305
 *
 
306
 *   std::size_t bytes_transferred           // Number of bytes copied into the
 
307
 *                                           // buffers. If an error occurred,
 
308
 *                                           // this will be the  number of
 
309
 *                                           // bytes successfully transferred
 
310
 *                                           // prior to the error.
 
311
 * ); @endcode
 
312
 * Regardless of whether the asynchronous operation completes immediately or
 
313
 * not, the handler will not be invoked from within this function. Invocation of
 
314
 * the handler will be performed in a manner equivalent to using
 
315
 * asio::io_service::post().
 
316
 *
 
317
 * @par Example
 
318
 * To read into a single data buffer use the @ref buffer function as follows:
 
319
 * @code
 
320
 * asio::async_read(s, asio::buffer(data, size), handler);
 
321
 * @endcode
 
322
 * See the @ref buffer documentation for information on reading into multiple
 
323
 * buffers in one go, and how to use it with arrays, boost::array or
 
324
 * std::vector.
 
325
 *
 
326
 * @note This overload is equivalent to calling:
 
327
 * @code asio::async_read(
 
328
 *     s, buffers,
 
329
 *     asio::transfer_all(),
 
330
 *     handler); @endcode
 
331
 */
 
332
template <typename AsyncReadStream, typename MutableBufferSequence,
 
333
    typename ReadHandler>
 
334
void async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
 
335
    ReadHandler handler);
 
336
 
 
337
/// Start an asynchronous operation to read a certain amount of data from a
 
338
/// stream.
 
339
/**
 
340
 * This function is used to asynchronously read a certain number of bytes of
 
341
 * data from a stream. The function call always returns immediately. The
 
342
 * asynchronous operation will continue until one of the following conditions is
 
343
 * true:
 
344
 *
 
345
 * @li The supplied buffers are full. That is, the bytes transferred is equal to
 
346
 * the sum of the buffer sizes.
 
347
 *
 
348
 * @li The completion_condition function object returns true.
 
349
 *
 
350
 * @param s The stream from which the data is to be read. The type must support
 
351
 * the AsyncReadStream concept.
 
352
 *
 
353
 * @param buffers One or more buffers into which the data will be read. The sum
 
354
 * of the buffer sizes indicates the maximum number of bytes to read from the
 
355
 * stream. Although the buffers object may be copied as necessary, ownership of
 
356
 * the underlying memory blocks is retained by the caller, which must guarantee
 
357
 * that they remain valid until the handler is called.
 
358
 *
 
359
 * @param completion_condition The function object to be called to determine
 
360
 * whether the read operation is complete. The signature of the function object
 
361
 * must be:
 
362
 * @code bool completion_condition(
 
363
 *   const asio::error_code& error, // Result of latest read_some
 
364
 *                                           // operation.
 
365
 *
 
366
 *   std::size_t bytes_transferred           // Number of bytes transferred
 
367
 *                                           // so far.
 
368
 * ); @endcode
 
369
 * A return value of true indicates that the read operation is complete. False
 
370
 * indicates that further calls to the stream's async_read_some function are
 
371
 * required.
 
372
 *
 
373
 * @param handler The handler to be called when the read operation completes.
 
374
 * Copies will be made of the handler as required. The function signature of the
 
375
 * handler must be:
 
376
 * @code void handler(
 
377
 *   const asio::error_code& error, // Result of operation.
 
378
 *
 
379
 *   std::size_t bytes_transferred           // Number of bytes copied into the
 
380
 *                                           // buffers. If an error occurred,
 
381
 *                                           // this will be the  number of
 
382
 *                                           // bytes successfully transferred
 
383
 *                                           // prior to the error.
 
384
 * ); @endcode
 
385
 * Regardless of whether the asynchronous operation completes immediately or
 
386
 * not, the handler will not be invoked from within this function. Invocation of
 
387
 * the handler will be performed in a manner equivalent to using
 
388
 * asio::io_service::post().
 
389
 *
 
390
 * @par Example
 
391
 * To read into a single data buffer use the @ref buffer function as follows:
 
392
 * @code asio::async_read(s,
 
393
 *     asio::buffer(data, size),
 
394
 *     asio::transfer_at_least(32),
 
395
 *     handler); @endcode
 
396
 * See the @ref buffer documentation for information on reading into multiple
 
397
 * buffers in one go, and how to use it with arrays, boost::array or
 
398
 * std::vector.
 
399
 */
 
400
template <typename AsyncReadStream, typename MutableBufferSequence,
 
401
    typename CompletionCondition, typename ReadHandler>
 
402
void async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
 
403
    CompletionCondition completion_condition, ReadHandler handler);
 
404
 
 
405
/// Start an asynchronous operation to read a certain amount of data from a
 
406
/// stream.
 
407
/**
 
408
 * This function is used to asynchronously read a certain number of bytes of
 
409
 * data from a stream. The function call always returns immediately. The
 
410
 * asynchronous operation will continue until one of the following conditions is
 
411
 * true:
 
412
 *
 
413
 * @li An error occurred.
 
414
 *
 
415
 * This operation is implemented in terms of one or more calls to the stream's
 
416
 * async_read_some function.
 
417
 *
 
418
 * @param s The stream from which the data is to be read. The type must support
 
419
 * the AsyncReadStream concept.
 
420
 *
 
421
 * @param b A basic_streambuf object into which the data will be read. Ownership
 
422
 * of the streambuf is retained by the caller, which must guarantee that it
 
423
 * remains valid until the handler is called.
 
424
 *
 
425
 * @param handler The handler to be called when the read operation completes.
 
426
 * Copies will be made of the handler as required. The function signature of the
 
427
 * handler must be:
 
428
 * @code void handler(
 
429
 *   const asio::error_code& error, // Result of operation.
 
430
 *
 
431
 *   std::size_t bytes_transferred           // Number of bytes copied into the
 
432
 *                                           // buffers. If an error occurred,
 
433
 *                                           // this will be the  number of
 
434
 *                                           // bytes successfully transferred
 
435
 *                                           // prior to the error.
 
436
 * ); @endcode
 
437
 * Regardless of whether the asynchronous operation completes immediately or
 
438
 * not, the handler will not be invoked from within this function. Invocation of
 
439
 * the handler will be performed in a manner equivalent to using
 
440
 * asio::io_service::post().
 
441
 *
 
442
 * @note This overload is equivalent to calling:
 
443
 * @code asio::async_read(
 
444
 *     s, b,
 
445
 *     asio::transfer_all(),
 
446
 *     handler); @endcode
 
447
 */
 
448
template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
 
449
void async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
 
450
    ReadHandler handler);
 
451
 
 
452
/// Start an asynchronous operation to read a certain amount of data from a
 
453
/// stream.
 
454
/**
 
455
 * This function is used to asynchronously read a certain number of bytes of
 
456
 * data from a stream. The function call always returns immediately. The
 
457
 * asynchronous operation will continue until one of the following conditions is
 
458
 * true:
 
459
 *
 
460
 * @li The completion_condition function object returns true.
 
461
 *
 
462
 * This operation is implemented in terms of one or more calls to the stream's
 
463
 * async_read_some function.
 
464
 *
 
465
 * @param s The stream from which the data is to be read. The type must support
 
466
 * the AsyncReadStream concept.
 
467
 *
 
468
 * @param b A basic_streambuf object into which the data will be read. Ownership
 
469
 * of the streambuf is retained by the caller, which must guarantee that it
 
470
 * remains valid until the handler is called.
 
471
 *
 
472
 * @param completion_condition The function object to be called to determine
 
473
 * whether the read operation is complete. The signature of the function object
 
474
 * must be:
 
475
 * @code bool completion_condition(
 
476
 *   const asio::error_code& error, // Result of latest read_some
 
477
 *                                           // operation.
 
478
 *
 
479
 *   std::size_t bytes_transferred           // Number of bytes transferred
 
480
 *                                           // so far.
 
481
 * ); @endcode
 
482
 * A return value of true indicates that the read operation is complete. False
 
483
 * indicates that further calls to the stream's async_read_some function are
 
484
 * required.
 
485
 *
 
486
 * @param handler The handler to be called when the read operation completes.
 
487
 * Copies will be made of the handler as required. The function signature of the
 
488
 * handler must be:
 
489
 * @code void handler(
 
490
 *   const asio::error_code& error, // Result of operation.
 
491
 *
 
492
 *   std::size_t bytes_transferred           // Number of bytes copied into the
 
493
 *                                           // buffers. If an error occurred,
 
494
 *                                           // this will be the  number of
 
495
 *                                           // bytes successfully transferred
 
496
 *                                           // prior to the error.
 
497
 * ); @endcode
 
498
 * Regardless of whether the asynchronous operation completes immediately or
 
499
 * not, the handler will not be invoked from within this function. Invocation of
 
500
 * the handler will be performed in a manner equivalent to using
 
501
 * asio::io_service::post().
 
502
 */
 
503
template <typename AsyncReadStream, typename Allocator,
 
504
    typename CompletionCondition, typename ReadHandler>
 
505
void async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
 
506
    CompletionCondition completion_condition, ReadHandler handler);
 
507
 
 
508
/*@}*/
 
509
 
 
510
} // namespace asio
 
511
 
 
512
#include "asio/impl/read.ipp"
 
513
 
 
514
#include "asio/detail/pop_options.hpp"
 
515
 
 
516
#endif // ASIO_READ_HPP