fix doc example typo
[boost.git] / boost / asio / read_at.hpp
blob5b1d5eac6bad33dd926fd8669ff0cd47baaef023
1 //
2 // read_at.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 //
11 #ifndef BOOST_ASIO_READ_AT_HPP
12 #define BOOST_ASIO_READ_AT_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
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 <cstddef>
22 #include <boost/config.hpp>
23 #include <boost/cstdint.hpp>
24 #include <boost/asio/detail/pop_options.hpp>
26 #include <boost/asio/basic_streambuf.hpp>
27 #include <boost/asio/error.hpp>
29 namespace boost {
30 namespace asio {
32 /**
33 * @defgroup read_at boost::asio::read_at
35 * @brief Attempt to read a certain amount of data at the specified offset
36 * before returning.
38 /*@{*/
40 /// Attempt to read a certain amount of data at the specified offset before
41 /// returning.
42 /**
43 * This function is used to read a certain number of bytes of data from a
44 * random access device at the specified offset. The call will block until one
45 * of the following conditions is true:
47 * @li The supplied buffers are full. That is, the bytes transferred is equal to
48 * the sum of the buffer sizes.
50 * @li An error occurred.
52 * This operation is implemented in terms of zero or more calls to the device's
53 * read_some_at function.
55 * @param d The device from which the data is to be read. The type must support
56 * the SyncRandomAccessReadDevice concept.
58 * @param offset The offset at which the data will be read.
60 * @param buffers One or more buffers into which the data will be read. The sum
61 * of the buffer sizes indicates the maximum number of bytes to read from the
62 * device.
64 * @returns The number of bytes transferred.
66 * @throws boost::system::system_error Thrown on failure.
68 * @par Example
69 * To read into a single data buffer use the @ref buffer function as follows:
70 * @code boost::asio::read_at(d, 42, boost::asio::buffer(data, size)); @endcode
71 * See the @ref buffer documentation for information on reading into multiple
72 * buffers in one go, and how to use it with arrays, boost::array or
73 * std::vector.
75 * @note This overload is equivalent to calling:
76 * @code boost::asio::read_at(
77 * d, 42, buffers,
78 * boost::asio::transfer_all()); @endcode
80 template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence>
81 std::size_t read_at(SyncRandomAccessReadDevice& d,
82 boost::uint64_t offset, const MutableBufferSequence& buffers);
84 /// Attempt to read a certain amount of data at the specified offset before
85 /// returning.
86 /**
87 * This function is used to read a certain number of bytes of data from a
88 * random access device at the specified offset. The call will block until one
89 * of the following conditions is true:
91 * @li The supplied buffers are full. That is, the bytes transferred is equal to
92 * the sum of the buffer sizes.
94 * @li The completion_condition function object returns 0.
96 * This operation is implemented in terms of zero or more calls to the device's
97 * read_some_at function.
99 * @param d The device from which the data is to be read. The type must support
100 * the SyncRandomAccessReadDevice concept.
102 * @param offset The offset at which the data will be read.
104 * @param buffers One or more buffers into which the data will be read. The sum
105 * of the buffer sizes indicates the maximum number of bytes to read from the
106 * device.
108 * @param completion_condition The function object to be called to determine
109 * whether the read operation is complete. The signature of the function object
110 * must be:
111 * @code std::size_t completion_condition(
112 * // Result of latest read_some_at operation.
113 * const boost::system::error_code& error,
115 * // Number of bytes transferred so far.
116 * std::size_t bytes_transferred
117 * ); @endcode
118 * A return value of 0 indicates that the read operation is complete. A non-zero
119 * return value indicates the maximum number of bytes to be read on the next
120 * call to the device's read_some_at function.
122 * @returns The number of bytes transferred.
124 * @throws boost::system::system_error Thrown on failure.
126 * @par Example
127 * To read into a single data buffer use the @ref buffer function as follows:
128 * @code boost::asio::read_at(d, 42, boost::asio::buffer(data, size),
129 * boost::asio::transfer_at_least(32)); @endcode
130 * See the @ref buffer documentation for information on reading into multiple
131 * buffers in one go, and how to use it with arrays, boost::array or
132 * std::vector.
134 template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence,
135 typename CompletionCondition>
136 std::size_t read_at(SyncRandomAccessReadDevice& d,
137 boost::uint64_t offset, const MutableBufferSequence& buffers,
138 CompletionCondition completion_condition);
140 /// Attempt to read a certain amount of data at the specified offset before
141 /// returning.
143 * This function is used to read a certain number of bytes of data from a
144 * random access device at the specified offset. The call will block until one
145 * of the following conditions is true:
147 * @li The supplied buffers are full. That is, the bytes transferred is equal to
148 * the sum of the buffer sizes.
150 * @li The completion_condition function object returns 0.
152 * This operation is implemented in terms of zero or more calls to the device's
153 * read_some_at function.
155 * @param d The device from which the data is to be read. The type must support
156 * the SyncRandomAccessReadDevice concept.
158 * @param offset The offset at which the data will be read.
160 * @param buffers One or more buffers into which the data will be read. The sum
161 * of the buffer sizes indicates the maximum number of bytes to read from the
162 * device.
164 * @param completion_condition The function object to be called to determine
165 * whether the read operation is complete. The signature of the function object
166 * must be:
167 * @code std::size_t completion_condition(
168 * // Result of latest read_some_at operation.
169 * const boost::system::error_code& error,
171 * // Number of bytes transferred so far.
172 * std::size_t bytes_transferred
173 * ); @endcode
174 * A return value of 0 indicates that the read operation is complete. A non-zero
175 * return value indicates the maximum number of bytes to be read on the next
176 * call to the device's read_some_at function.
178 * @param ec Set to indicate what error occurred, if any.
180 * @returns The number of bytes read. If an error occurs, returns the total
181 * number of bytes successfully transferred prior to the error.
183 template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence,
184 typename CompletionCondition>
185 std::size_t read_at(SyncRandomAccessReadDevice& d,
186 boost::uint64_t offset, const MutableBufferSequence& buffers,
187 CompletionCondition completion_condition, boost::system::error_code& ec);
189 /// Attempt to read a certain amount of data at the specified offset before
190 /// returning.
192 * This function is used to read a certain number of bytes of data from a
193 * random access device at the specified offset. The call will block until one
194 * of the following conditions is true:
196 * @li An error occurred.
198 * This operation is implemented in terms of zero or more calls to the device's
199 * read_some_at function.
201 * @param d The device from which the data is to be read. The type must support
202 * the SyncRandomAccessReadDevice concept.
204 * @param offset The offset at which the data will be read.
206 * @param b The basic_streambuf object into which the data will be read.
208 * @returns The number of bytes transferred.
210 * @throws boost::system::system_error Thrown on failure.
212 * @note This overload is equivalent to calling:
213 * @code boost::asio::read_at(
214 * d, 42, b,
215 * boost::asio::transfer_all()); @endcode
217 template <typename SyncRandomAccessReadDevice, typename Allocator>
218 std::size_t read_at(SyncRandomAccessReadDevice& d,
219 boost::uint64_t offset, basic_streambuf<Allocator>& b);
221 /// Attempt to read a certain amount of data at the specified offset before
222 /// returning.
224 * This function is used to read a certain number of bytes of data from a
225 * random access device at the specified offset. The call will block until one
226 * of the following conditions is true:
228 * @li The completion_condition function object returns 0.
230 * This operation is implemented in terms of zero or more calls to the device's
231 * read_some_at function.
233 * @param d The device from which the data is to be read. The type must support
234 * the SyncRandomAccessReadDevice concept.
236 * @param offset The offset at which the data will be read.
238 * @param b The basic_streambuf object into which the data will be read.
240 * @param completion_condition The function object to be called to determine
241 * whether the read operation is complete. The signature of the function object
242 * must be:
243 * @code std::size_t completion_condition(
244 * // Result of latest read_some_at operation.
245 * const boost::system::error_code& error,
247 * // Number of bytes transferred so far.
248 * std::size_t bytes_transferred
249 * ); @endcode
250 * A return value of 0 indicates that the read operation is complete. A non-zero
251 * return value indicates the maximum number of bytes to be read on the next
252 * call to the device's read_some_at function.
254 * @returns The number of bytes transferred.
256 * @throws boost::system::system_error Thrown on failure.
258 template <typename SyncRandomAccessReadDevice, typename Allocator,
259 typename CompletionCondition>
260 std::size_t read_at(SyncRandomAccessReadDevice& d,
261 boost::uint64_t offset, basic_streambuf<Allocator>& b,
262 CompletionCondition completion_condition);
264 /// Attempt to read a certain amount of data at the specified offset before
265 /// returning.
267 * This function is used to read a certain number of bytes of data from a
268 * random access device at the specified offset. The call will block until one
269 * of the following conditions is true:
271 * @li The completion_condition function object returns 0.
273 * This operation is implemented in terms of zero or more calls to the device's
274 * read_some_at function.
276 * @param d The device from which the data is to be read. The type must support
277 * the SyncRandomAccessReadDevice concept.
279 * @param offset The offset at which the data will be read.
281 * @param b The basic_streambuf object into which the data will be read.
283 * @param completion_condition The function object to be called to determine
284 * whether the read operation is complete. The signature of the function object
285 * must be:
286 * @code std::size_t completion_condition(
287 * // Result of latest read_some_at operation.
288 * const boost::system::error_code& error,
290 * // Number of bytes transferred so far.
291 * std::size_t bytes_transferred
292 * ); @endcode
293 * A return value of 0 indicates that the read operation is complete. A non-zero
294 * return value indicates the maximum number of bytes to be read on the next
295 * call to the device's read_some_at function.
297 * @param ec Set to indicate what error occurred, if any.
299 * @returns The number of bytes read. If an error occurs, returns the total
300 * number of bytes successfully transferred prior to the error.
302 template <typename SyncRandomAccessReadDevice, typename Allocator,
303 typename CompletionCondition>
304 std::size_t read_at(SyncRandomAccessReadDevice& d,
305 boost::uint64_t offset, basic_streambuf<Allocator>& b,
306 CompletionCondition completion_condition, boost::system::error_code& ec);
308 /*@}*/
310 * @defgroup async_read_at boost::asio::async_read_at
312 * @brief Start an asynchronous operation to read a certain amount of data at
313 * the specified offset.
315 /*@{*/
317 /// Start an asynchronous operation to read a certain amount of data at the
318 /// specified offset.
320 * This function is used to asynchronously read a certain number of bytes of
321 * data from a random access device at the specified offset. The function call
322 * always returns immediately. The asynchronous operation will continue until
323 * one of the following conditions is true:
325 * @li The supplied buffers are full. That is, the bytes transferred is equal to
326 * the sum of the buffer sizes.
328 * @li An error occurred.
330 * This operation is implemented in terms of zero or more calls to the device's
331 * async_read_some_at function.
333 * @param d The device from which the data is to be read. The type must support
334 * the AsyncRandomAccessReadDevice concept.
336 * @param offset The offset at which the data will be read.
338 * @param buffers One or more buffers into which the data will be read. The sum
339 * of the buffer sizes indicates the maximum number of bytes to read from the
340 * device. Although the buffers object may be copied as necessary, ownership of
341 * the underlying memory blocks is retained by the caller, which must guarantee
342 * that they remain valid until the handler is called.
344 * @param handler The handler to be called when the read operation completes.
345 * Copies will be made of the handler as required. The function signature of the
346 * handler must be:
347 * @code void handler(
348 * // Result of operation.
349 * const boost::system::error_code& error,
351 * // Number of bytes copied into the buffers. If an error
352 * // occurred, this will be the number of bytes successfully
353 * // transferred prior to the error.
354 * std::size_t bytes_transferred
355 * ); @endcode
356 * Regardless of whether the asynchronous operation completes immediately or
357 * not, the handler will not be invoked from within this function. Invocation of
358 * the handler will be performed in a manner equivalent to using
359 * boost::asio::io_service::post().
361 * @par Example
362 * To read into a single data buffer use the @ref buffer function as follows:
363 * @code
364 * boost::asio::async_read_at(d, 42, boost::asio::buffer(data, size), handler);
365 * @endcode
366 * See the @ref buffer documentation for information on reading into multiple
367 * buffers in one go, and how to use it with arrays, boost::array or
368 * std::vector.
370 * @note This overload is equivalent to calling:
371 * @code boost::asio::async_read_at(
372 * d, 42, buffers,
373 * boost::asio::transfer_all(),
374 * handler); @endcode
376 template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
377 typename ReadHandler>
378 void async_read_at(AsyncRandomAccessReadDevice& d, boost::uint64_t offset,
379 const MutableBufferSequence& buffers, ReadHandler handler);
381 /// Start an asynchronous operation to read a certain amount of data at the
382 /// specified offset.
384 * This function is used to asynchronously read a certain number of bytes of
385 * data from a random access device at the specified offset. The function call
386 * always returns immediately. The asynchronous operation will continue until
387 * one of the following conditions is true:
389 * @li The supplied buffers are full. That is, the bytes transferred is equal to
390 * the sum of the buffer sizes.
392 * @li The completion_condition function object returns 0.
394 * @param d The device from which the data is to be read. The type must support
395 * the AsyncRandomAccessReadDevice concept.
397 * @param offset The offset at which the data will be read.
399 * @param buffers One or more buffers into which the data will be read. The sum
400 * of the buffer sizes indicates the maximum number of bytes to read from the
401 * device. Although the buffers object may be copied as necessary, ownership of
402 * the underlying memory blocks is retained by the caller, which must guarantee
403 * that they remain valid until the handler is called.
405 * @param completion_condition The function object to be called to determine
406 * whether the read operation is complete. The signature of the function object
407 * must be:
408 * @code std::size_t completion_condition(
409 * // Result of latest async_read_some_at operation.
410 * const boost::system::error_code& error,
412 * // Number of bytes transferred so far.
413 * std::size_t bytes_transferred
414 * ); @endcode
415 * A return value of 0 indicates that the read operation is complete. A non-zero
416 * return value indicates the maximum number of bytes to be read on the next
417 * call to the device's async_read_some_at function.
419 * @param handler The handler to be called when the read operation completes.
420 * Copies will be made of the handler as required. The function signature of the
421 * handler must be:
422 * @code void handler(
423 * // Result of operation.
424 * const boost::system::error_code& error,
426 * // Number of bytes copied into the buffers. If an error
427 * // occurred, this will be the number of bytes successfully
428 * // transferred prior to the error.
429 * std::size_t bytes_transferred
430 * ); @endcode
431 * Regardless of whether the asynchronous operation completes immediately or
432 * not, the handler will not be invoked from within this function. Invocation of
433 * the handler will be performed in a manner equivalent to using
434 * boost::asio::io_service::post().
436 * @par Example
437 * To read into a single data buffer use the @ref buffer function as follows:
438 * @code boost::asio::async_read_at(d, 42,
439 * boost::asio::buffer(data, size),
440 * boost::asio::transfer_at_least(32),
441 * handler); @endcode
442 * See the @ref buffer documentation for information on reading into multiple
443 * buffers in one go, and how to use it with arrays, boost::array or
444 * std::vector.
446 template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
447 typename CompletionCondition, typename ReadHandler>
448 void async_read_at(AsyncRandomAccessReadDevice& d,
449 boost::uint64_t offset, const MutableBufferSequence& buffers,
450 CompletionCondition completion_condition, ReadHandler handler);
452 /// Start an asynchronous operation to read a certain amount of data at the
453 /// specified offset.
455 * This function is used to asynchronously read a certain number of bytes of
456 * data from a random access device at the specified offset. The function call
457 * always returns immediately. The asynchronous operation will continue until
458 * one of the following conditions is true:
460 * @li An error occurred.
462 * This operation is implemented in terms of zero or more calls to the device's
463 * async_read_some_at function.
465 * @param d The device from which the data is to be read. The type must support
466 * the AsyncRandomAccessReadDevice concept.
468 * @param offset The offset at which the data will be read.
470 * @param b A basic_streambuf object into which the data will be read. Ownership
471 * of the streambuf is retained by the caller, which must guarantee that it
472 * remains valid until the handler is called.
474 * @param handler The handler to be called when the read operation completes.
475 * Copies will be made of the handler as required. The function signature of the
476 * handler must be:
477 * @code void handler(
478 * // Result of operation.
479 * const boost::system::error_code& error,
481 * // Number of bytes copied into the buffers. If an error
482 * // occurred, this will be the number of bytes successfully
483 * // transferred prior to the error.
484 * std::size_t bytes_transferred
485 * ); @endcode
486 * Regardless of whether the asynchronous operation completes immediately or
487 * not, the handler will not be invoked from within this function. Invocation of
488 * the handler will be performed in a manner equivalent to using
489 * boost::asio::io_service::post().
491 * @note This overload is equivalent to calling:
492 * @code boost::asio::async_read_at(
493 * d, 42, b,
494 * boost::asio::transfer_all(),
495 * handler); @endcode
497 template <typename AsyncRandomAccessReadDevice, typename Allocator,
498 typename ReadHandler>
499 void async_read_at(AsyncRandomAccessReadDevice& d, boost::uint64_t offset,
500 basic_streambuf<Allocator>& b, ReadHandler handler);
502 /// Start an asynchronous operation to read a certain amount of data at the
503 /// specified offset.
505 * This function is used to asynchronously read a certain number of bytes of
506 * data from a random access device at the specified offset. The function call
507 * always returns immediately. The asynchronous operation will continue until
508 * one of the following conditions is true:
510 * @li The completion_condition function object returns 0.
512 * This operation is implemented in terms of zero or more calls to the device's
513 * async_read_some_at function.
515 * @param d The device from which the data is to be read. The type must support
516 * the AsyncRandomAccessReadDevice concept.
518 * @param offset The offset at which the data will be read.
520 * @param b A basic_streambuf object into which the data will be read. Ownership
521 * of the streambuf is retained by the caller, which must guarantee that it
522 * remains valid until the handler is called.
524 * @param completion_condition The function object to be called to determine
525 * whether the read operation is complete. The signature of the function object
526 * must be:
527 * @code std::size_t completion_condition(
528 * // Result of latest async_read_some_at operation.
529 * const boost::system::error_code& error,
531 * // Number of bytes transferred so far.
532 * std::size_t bytes_transferred
533 * ); @endcode
534 * A return value of 0 indicates that the read operation is complete. A non-zero
535 * return value indicates the maximum number of bytes to be read on the next
536 * call to the device's async_read_some_at function.
538 * @param handler The handler to be called when the read operation completes.
539 * Copies will be made of the handler as required. The function signature of the
540 * handler must be:
541 * @code void handler(
542 * // Result of operation.
543 * const boost::system::error_code& error,
545 * // Number of bytes copied into the buffers. If an error
546 * // occurred, this will be the number of bytes successfully
547 * // transferred prior to the error.
548 * std::size_t bytes_transferred
549 * ); @endcode
550 * Regardless of whether the asynchronous operation completes immediately or
551 * not, the handler will not be invoked from within this function. Invocation of
552 * the handler will be performed in a manner equivalent to using
553 * boost::asio::io_service::post().
555 template <typename AsyncRandomAccessReadDevice, typename Allocator,
556 typename CompletionCondition, typename ReadHandler>
557 void async_read_at(AsyncRandomAccessReadDevice& d,
558 boost::uint64_t offset, basic_streambuf<Allocator>& b,
559 CompletionCondition completion_condition, ReadHandler handler);
561 /*@}*/
563 } // namespace asio
564 } // namespace boost
566 #include <boost/asio/impl/read_at.ipp>
568 #include <boost/asio/detail/pop_options.hpp>
570 #endif // BOOST_ASIO_READ_AT_HPP