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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2010-08-10 12:59:37 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810125937-jbcmmf17y8yo9hgz
Tags: 0.15.0-0ubuntu1
* New upstream version.
* debian/patches/100_fix_html_docs.patch: refreshed.
* debian/control: bump up standards-version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

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