Realistic 3D camera system
3D camera system components
read_at.hpp
Go to the documentation of this file.
1 //
2 // impl/read_at.hpp
3 // ~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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_IMPL_READ_AT_HPP
12 #define ASIO_IMPL_READ_AT_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include <algorithm>
19 #include "asio/buffer.hpp"
31 #include "asio/error.hpp"
32 
34 
35 namespace asio {
36 
37 template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence,
38  typename CompletionCondition>
39 std::size_t read_at(SyncRandomAccessReadDevice& d,
40  uint64_t offset, const MutableBufferSequence& buffers,
41  CompletionCondition completion_condition, asio::error_code& ec)
42 {
43  ec = asio::error_code();
45  mutable_buffer, MutableBufferSequence> tmp(buffers);
46  std::size_t total_transferred = 0;
48  completion_condition(ec, total_transferred)));
49  while (tmp.begin() != tmp.end())
50  {
51  std::size_t bytes_transferred = d.read_some_at(
52  offset + total_transferred, tmp, ec);
53  tmp.consume(bytes_transferred);
54  total_transferred += bytes_transferred;
56  completion_condition(ec, total_transferred)));
57  }
58  return total_transferred;
59 }
60 
61 template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence>
62 inline std::size_t read_at(SyncRandomAccessReadDevice& d,
63  uint64_t offset, const MutableBufferSequence& buffers)
64 {
66  std::size_t bytes_transferred = read_at(
67  d, offset, buffers, transfer_all(), ec);
68  asio::detail::throw_error(ec, "read_at");
69  return bytes_transferred;
70 }
71 
72 template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence>
73 inline std::size_t read_at(SyncRandomAccessReadDevice& d,
74  uint64_t offset, const MutableBufferSequence& buffers,
75  asio::error_code& ec)
76 {
77  return read_at(d, offset, buffers, transfer_all(), ec);
78 }
79 
80 template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence,
81  typename CompletionCondition>
82 inline std::size_t read_at(SyncRandomAccessReadDevice& d,
83  uint64_t offset, const MutableBufferSequence& buffers,
84  CompletionCondition completion_condition)
85 {
87  std::size_t bytes_transferred = read_at(
88  d, offset, buffers, completion_condition, ec);
89  asio::detail::throw_error(ec, "read_at");
90  return bytes_transferred;
91 }
92 
93 #if !defined(ASIO_NO_IOSTREAM)
94 
95 template <typename SyncRandomAccessReadDevice, typename Allocator,
96  typename CompletionCondition>
97 std::size_t read_at(SyncRandomAccessReadDevice& d,
99  CompletionCondition completion_condition, asio::error_code& ec)
100 {
101  ec = asio::error_code();
102  std::size_t total_transferred = 0;
103  std::size_t max_size = detail::adapt_completion_condition_result(
104  completion_condition(ec, total_transferred));
105  std::size_t bytes_available = read_size_helper(b, max_size);
106  while (bytes_available > 0)
107  {
108  std::size_t bytes_transferred = d.read_some_at(
109  offset + total_transferred, b.prepare(bytes_available), ec);
110  b.commit(bytes_transferred);
111  total_transferred += bytes_transferred;
113  completion_condition(ec, total_transferred));
114  bytes_available = read_size_helper(b, max_size);
115  }
116  return total_transferred;
117 }
118 
119 template <typename SyncRandomAccessReadDevice, typename Allocator>
120 inline std::size_t read_at(SyncRandomAccessReadDevice& d,
122 {
123  asio::error_code ec;
124  std::size_t bytes_transferred = read_at(
125  d, offset, b, transfer_all(), ec);
126  asio::detail::throw_error(ec, "read_at");
127  return bytes_transferred;
128 }
129 
130 template <typename SyncRandomAccessReadDevice, typename Allocator>
131 inline std::size_t read_at(SyncRandomAccessReadDevice& d,
133  asio::error_code& ec)
134 {
135  return read_at(d, offset, b, transfer_all(), ec);
136 }
137 
138 template <typename SyncRandomAccessReadDevice, typename Allocator,
139  typename CompletionCondition>
140 inline std::size_t read_at(SyncRandomAccessReadDevice& d,
142  CompletionCondition completion_condition)
143 {
144  asio::error_code ec;
145  std::size_t bytes_transferred = read_at(
146  d, offset, b, completion_condition, ec);
147  asio::detail::throw_error(ec, "read_at");
148  return bytes_transferred;
149 }
150 
151 #endif // !defined(ASIO_NO_IOSTREAM)
152 
153 namespace detail
154 {
155  template <typename AsyncRandomAccessReadDevice,
156  typename MutableBufferSequence, typename CompletionCondition,
157  typename ReadHandler>
159  : detail::base_from_completion_cond<CompletionCondition>
160  {
161  public:
162  read_at_op(AsyncRandomAccessReadDevice& device,
163  uint64_t offset, const MutableBufferSequence& buffers,
164  CompletionCondition completion_condition, ReadHandler& handler)
165  : detail::base_from_completion_cond<
166  CompletionCondition>(completion_condition),
167  device_(device),
168  offset_(offset),
169  buffers_(buffers),
170  start_(0),
172  handler_(ASIO_MOVE_CAST(ReadHandler)(handler))
173  {
174  }
175 
176 #if defined(ASIO_HAS_MOVE)
177  read_at_op(const read_at_op& other)
179  device_(other.device_),
180  offset_(other.offset_),
181  buffers_(other.buffers_),
182  start_(other.start_),
184  handler_(other.handler_)
185  {
186  }
187 
188  read_at_op(read_at_op&& other)
190  device_(other.device_),
191  offset_(other.offset_),
192  buffers_(other.buffers_),
193  start_(other.start_),
195  handler_(ASIO_MOVE_CAST(ReadHandler)(other.handler_))
196  {
197  }
198 #endif // defined(ASIO_HAS_MOVE)
199 
200  void operator()(const asio::error_code& ec,
201  std::size_t bytes_transferred, int start = 0)
202  {
203  switch (start_ = start)
204  {
205  case 1:
207  for (;;)
208  {
209  device_.async_read_some_at(offset_ + total_transferred_,
211  return; default:
212  total_transferred_ += bytes_transferred;
213  buffers_.consume(bytes_transferred);
215  if ((!ec && bytes_transferred == 0)
216  || buffers_.begin() == buffers_.end())
217  break;
218  }
219 
220  handler_(ec, static_cast<const std::size_t&>(total_transferred_));
221  }
222  }
223 
224  //private:
225  AsyncRandomAccessReadDevice& device_;
226  uint64_t offset_;
228  mutable_buffer, MutableBufferSequence> buffers_;
229  int start_;
230  std::size_t total_transferred_;
231  ReadHandler handler_;
232  };
233 
234  template <typename AsyncRandomAccessReadDevice,
235  typename CompletionCondition, typename ReadHandler>
236  class read_at_op<AsyncRandomAccessReadDevice,
237  asio::mutable_buffers_1, CompletionCondition, ReadHandler>
238  : detail::base_from_completion_cond<CompletionCondition>
239  {
240  public:
241  read_at_op(AsyncRandomAccessReadDevice& device,
242  uint64_t offset, const asio::mutable_buffers_1& buffers,
243  CompletionCondition completion_condition, ReadHandler& handler)
244  : detail::base_from_completion_cond<
245  CompletionCondition>(completion_condition),
246  device_(device),
247  offset_(offset),
248  buffer_(buffers),
249  start_(0),
251  handler_(ASIO_MOVE_CAST(ReadHandler)(handler))
252  {
253  }
254 
255 #if defined(ASIO_HAS_MOVE)
256  read_at_op(const read_at_op& other)
258  device_(other.device_),
259  offset_(other.offset_),
260  buffer_(other.buffer_),
261  start_(other.start_),
263  handler_(other.handler_)
264  {
265  }
266 
267  read_at_op(read_at_op&& other)
269  device_(other.device_),
270  offset_(other.offset_),
271  buffer_(other.buffer_),
272  start_(other.start_),
274  handler_(ASIO_MOVE_CAST(ReadHandler)(other.handler_))
275  {
276  }
277 #endif // defined(ASIO_HAS_MOVE)
278 
279  void operator()(const asio::error_code& ec,
280  std::size_t bytes_transferred, int start = 0)
281  {
282  std::size_t n = 0;
283  switch (start_ = start)
284  {
285  case 1:
287  for (;;)
288  {
289  device_.async_read_some_at(offset_ + total_transferred_,
290  asio::buffer(buffer_ + total_transferred_, n),
291  ASIO_MOVE_CAST(read_at_op)(*this));
292  return; default:
293  total_transferred_ += bytes_transferred;
294  if ((!ec && bytes_transferred == 0)
295  || (n = this->check_for_completion(ec, total_transferred_)) == 0
296  || total_transferred_ == asio::buffer_size(buffer_))
297  break;
298  }
299 
300  handler_(ec, static_cast<const std::size_t&>(total_transferred_));
301  }
302  }
303 
304  //private:
305  AsyncRandomAccessReadDevice& device_;
306  uint64_t offset_;
308  int start_;
309  std::size_t total_transferred_;
310  ReadHandler handler_;
311  };
312 
313  template <typename AsyncRandomAccessReadDevice, typename Elem,
314  typename CompletionCondition, typename ReadHandler>
315  class read_at_op<AsyncRandomAccessReadDevice, boost::array<Elem, 2>,
316  CompletionCondition, ReadHandler>
317  : detail::base_from_completion_cond<CompletionCondition>
318  {
319  public:
320  read_at_op(AsyncRandomAccessReadDevice& device,
321  uint64_t offset, const boost::array<Elem, 2>& buffers,
322  CompletionCondition completion_condition, ReadHandler& handler)
323  : detail::base_from_completion_cond<
324  CompletionCondition>(completion_condition),
325  device_(device),
326  offset_(offset),
327  buffers_(buffers),
328  start_(0),
330  handler_(ASIO_MOVE_CAST(ReadHandler)(handler))
331  {
332  }
333 
334 #if defined(ASIO_HAS_MOVE)
335  read_at_op(const read_at_op& other)
337  device_(other.device_),
338  offset_(other.offset_),
339  buffers_(other.buffers_),
340  start_(other.start_),
342  handler_(other.handler_)
343  {
344  }
345 
346  read_at_op(read_at_op&& other)
348  device_(other.device_),
349  offset_(other.offset_),
350  buffers_(other.buffers_),
351  start_(other.start_),
353  handler_(ASIO_MOVE_CAST(ReadHandler)(other.handler_))
354  {
355  }
356 #endif // defined(ASIO_HAS_MOVE)
357 
358  void operator()(const asio::error_code& ec,
359  std::size_t bytes_transferred, int start = 0)
360  {
361  typename asio::detail::dependent_type<Elem,
362  boost::array<asio::mutable_buffer, 2> >::type bufs = {{
365  std::size_t buffer_size0 = asio::buffer_size(bufs[0]);
366  std::size_t buffer_size1 = asio::buffer_size(bufs[1]);
367  std::size_t n = 0;
368  switch (start_ = start)
369  {
370  case 1:
372  for (;;)
373  {
374  bufs[0] = asio::buffer(bufs[0] + total_transferred_, n);
375  bufs[1] = asio::buffer(
376  bufs[1] + (total_transferred_ < buffer_size0
377  ? 0 : total_transferred_ - buffer_size0),
378  n - asio::buffer_size(bufs[0]));
379  device_.async_read_some_at(offset_ + total_transferred_,
380  bufs, ASIO_MOVE_CAST(read_at_op)(*this));
381  return; default:
382  total_transferred_ += bytes_transferred;
383  if ((!ec && bytes_transferred == 0)
384  || (n = this->check_for_completion(ec, total_transferred_)) == 0
385  || total_transferred_ == buffer_size0 + buffer_size1)
386  break;
387  }
388 
389  handler_(ec, static_cast<const std::size_t&>(total_transferred_));
390  }
391  }
392 
393  //private:
394  AsyncRandomAccessReadDevice& device_;
395  uint64_t offset_;
397  int start_;
398  std::size_t total_transferred_;
399  ReadHandler handler_;
400  };
401 
402 #if defined(ASIO_HAS_STD_ARRAY)
403 
404  template <typename AsyncRandomAccessReadDevice, typename Elem,
405  typename CompletionCondition, typename ReadHandler>
406  class read_at_op<AsyncRandomAccessReadDevice, std::array<Elem, 2>,
407  CompletionCondition, ReadHandler>
408  : detail::base_from_completion_cond<CompletionCondition>
409  {
410  public:
411  read_at_op(AsyncRandomAccessReadDevice& device,
412  uint64_t offset, const std::array<Elem, 2>& buffers,
413  CompletionCondition completion_condition, ReadHandler& handler)
415  CompletionCondition>(completion_condition),
416  device_(device),
417  offset_(offset),
418  buffers_(buffers),
419  start_(0),
421  handler_(ASIO_MOVE_CAST(ReadHandler)(handler))
422  {
423  }
424 
425 #if defined(ASIO_HAS_MOVE)
426  read_at_op(const read_at_op& other)
428  device_(other.device_),
429  offset_(other.offset_),
430  buffers_(other.buffers_),
431  start_(other.start_),
433  handler_(other.handler_)
434  {
435  }
436 
437  read_at_op(read_at_op&& other)
439  device_(other.device_),
440  offset_(other.offset_),
441  buffers_(other.buffers_),
442  start_(other.start_),
444  handler_(ASIO_MOVE_CAST(ReadHandler)(other.handler_))
445  {
446  }
447 #endif // defined(ASIO_HAS_MOVE)
448 
449  void operator()(const asio::error_code& ec,
450  std::size_t bytes_transferred, int start = 0)
451  {
452  typename asio::detail::dependent_type<Elem,
453  std::array<asio::mutable_buffer, 2> >::type bufs = {{
456  std::size_t buffer_size0 = asio::buffer_size(bufs[0]);
457  std::size_t buffer_size1 = asio::buffer_size(bufs[1]);
458  std::size_t n = 0;
459  switch (start_ = start)
460  {
461  case 1:
463  for (;;)
464  {
465  bufs[0] = asio::buffer(bufs[0] + total_transferred_, n);
466  bufs[1] = asio::buffer(
467  bufs[1] + (total_transferred_ < buffer_size0
468  ? 0 : total_transferred_ - buffer_size0),
469  n - asio::buffer_size(bufs[0]));
470  device_.async_read_some_at(offset_ + total_transferred_,
471  bufs, ASIO_MOVE_CAST(read_at_op)(*this));
472  return; default:
473  total_transferred_ += bytes_transferred;
474  if ((!ec && bytes_transferred == 0)
475  || (n = this->check_for_completion(ec, total_transferred_)) == 0
476  || total_transferred_ == buffer_size0 + buffer_size1)
477  break;
478  }
479 
480  handler_(ec, static_cast<const std::size_t&>(total_transferred_));
481  }
482  }
483 
484  //private:
485  AsyncRandomAccessReadDevice& device_;
486  uint64_t offset_;
487  std::array<Elem, 2> buffers_;
488  int start_;
489  std::size_t total_transferred_;
490  ReadHandler handler_;
491  };
492 
493 #endif // defined(ASIO_HAS_STD_ARRAY)
494 
495  template <typename AsyncRandomAccessReadDevice,
496  typename MutableBufferSequence, typename CompletionCondition,
497  typename ReadHandler>
498  inline void* asio_handler_allocate(std::size_t size,
499  read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
500  CompletionCondition, ReadHandler>* this_handler)
501  {
503  size, this_handler->handler_);
504  }
505 
506  template <typename AsyncRandomAccessReadDevice,
507  typename MutableBufferSequence, typename CompletionCondition,
508  typename ReadHandler>
509  inline void asio_handler_deallocate(void* pointer, std::size_t size,
510  read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
511  CompletionCondition, ReadHandler>* this_handler)
512  {
514  pointer, size, this_handler->handler_);
515  }
516 
517  template <typename AsyncRandomAccessReadDevice,
518  typename MutableBufferSequence, typename CompletionCondition,
519  typename ReadHandler>
521  read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
522  CompletionCondition, ReadHandler>* this_handler)
523  {
524  return this_handler->start_ == 0 ? true
526  this_handler->handler_);
527  }
528 
529  template <typename Function, typename AsyncRandomAccessReadDevice,
530  typename MutableBufferSequence, typename CompletionCondition,
531  typename ReadHandler>
532  inline void asio_handler_invoke(Function& function,
533  read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
534  CompletionCondition, ReadHandler>* this_handler)
535  {
537  function, this_handler->handler_);
538  }
539 
540  template <typename Function, typename AsyncRandomAccessReadDevice,
541  typename MutableBufferSequence, typename CompletionCondition,
542  typename ReadHandler>
543  inline void asio_handler_invoke(const Function& function,
544  read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
545  CompletionCondition, ReadHandler>* this_handler)
546  {
548  function, this_handler->handler_);
549  }
550 
551  template <typename AsyncRandomAccessReadDevice,
552  typename MutableBufferSequence, typename CompletionCondition,
553  typename ReadHandler>
554  inline read_at_op<AsyncRandomAccessReadDevice,
555  MutableBufferSequence, CompletionCondition, ReadHandler>
556  make_read_at_op(AsyncRandomAccessReadDevice& d,
557  uint64_t offset, const MutableBufferSequence& buffers,
558  CompletionCondition completion_condition, ReadHandler handler)
559  {
560  return read_at_op<AsyncRandomAccessReadDevice,
561  MutableBufferSequence, CompletionCondition, ReadHandler>(
562  d, offset, buffers, completion_condition, handler);
563  }
564 } // namespace detail
565 
566 template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
567  typename CompletionCondition, typename ReadHandler>
568 inline ASIO_INITFN_RESULT_TYPE(ReadHandler,
569  void (asio::error_code, std::size_t))
570 async_read_at(AsyncRandomAccessReadDevice& d,
571  uint64_t offset, const MutableBufferSequence& buffers,
572  CompletionCondition completion_condition,
573  ASIO_MOVE_ARG(ReadHandler) handler)
574 {
575  // If you get an error on the following line it means that your handler does
576  // not meet the documented type requirements for a ReadHandler.
577  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
578 
580  ReadHandler, void (asio::error_code, std::size_t)> init(
581  ASIO_MOVE_CAST(ReadHandler)(handler));
582 
583  detail::read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
584  CompletionCondition, ASIO_HANDLER_TYPE(ReadHandler,
585  void (asio::error_code, std::size_t))>(
587  asio::error_code(), 0, 1);
588 
589  return init.result.get();
590 }
591 
592 template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
593  typename ReadHandler>
594 inline ASIO_INITFN_RESULT_TYPE(ReadHandler,
595  void (asio::error_code, std::size_t))
596 async_read_at(AsyncRandomAccessReadDevice& d,
597  uint64_t offset, const MutableBufferSequence& buffers,
598  ASIO_MOVE_ARG(ReadHandler) handler)
599 {
600  // If you get an error on the following line it means that your handler does
601  // not meet the documented type requirements for a ReadHandler.
602  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
603 
605  ReadHandler, void (asio::error_code, std::size_t)> init(
606  ASIO_MOVE_CAST(ReadHandler)(handler));
607 
608  detail::read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
610  void (asio::error_code, std::size_t))>(
611  d, offset, buffers, transfer_all(), init.handler)(
612  asio::error_code(), 0, 1);
613 
614  return init.result.get();
615 }
616 
617 #if !defined(ASIO_NO_IOSTREAM)
618 
619 namespace detail
620 {
621  template <typename AsyncRandomAccessReadDevice, typename Allocator,
622  typename CompletionCondition, typename ReadHandler>
624  : detail::base_from_completion_cond<CompletionCondition>
625  {
626  public:
627  read_at_streambuf_op(AsyncRandomAccessReadDevice& device,
628  uint64_t offset, basic_streambuf<Allocator>& streambuf,
629  CompletionCondition completion_condition, ReadHandler& handler)
630  : detail::base_from_completion_cond<
631  CompletionCondition>(completion_condition),
632  device_(device),
633  offset_(offset),
634  streambuf_(streambuf),
635  start_(0),
637  handler_(ASIO_MOVE_CAST(ReadHandler)(handler))
638  {
639  }
640 
641 #if defined(ASIO_HAS_MOVE)
644  device_(other.device_),
645  offset_(other.offset_),
646  streambuf_(other.streambuf_),
647  start_(other.start_),
649  handler_(other.handler_)
650  {
651  }
652 
655  device_(other.device_),
656  offset_(other.offset_),
657  streambuf_(other.streambuf_),
658  start_(other.start_),
660  handler_(ASIO_MOVE_CAST(ReadHandler)(other.handler_))
661  {
662  }
663 #endif // defined(ASIO_HAS_MOVE)
664 
665  void operator()(const asio::error_code& ec,
666  std::size_t bytes_transferred, int start = 0)
667  {
668  std::size_t max_size, bytes_available;
669  switch (start_ = start)
670  {
671  case 1:
672  max_size = this->check_for_completion(ec, total_transferred_);
673  bytes_available = read_size_helper(streambuf_, max_size);
674  for (;;)
675  {
676  device_.async_read_some_at(offset_ + total_transferred_,
677  streambuf_.prepare(bytes_available),
679  return; default:
680  total_transferred_ += bytes_transferred;
681  streambuf_.commit(bytes_transferred);
682  max_size = this->check_for_completion(ec, total_transferred_);
683  bytes_available = read_size_helper(streambuf_, max_size);
684  if ((!ec && bytes_transferred == 0) || bytes_available == 0)
685  break;
686  }
687 
688  handler_(ec, static_cast<const std::size_t&>(total_transferred_));
689  }
690  }
691 
692  //private:
693  AsyncRandomAccessReadDevice& device_;
694  uint64_t offset_;
696  int start_;
697  std::size_t total_transferred_;
698  ReadHandler handler_;
699  };
700 
701  template <typename AsyncRandomAccessReadDevice, typename Allocator,
702  typename CompletionCondition, typename ReadHandler>
703  inline void* asio_handler_allocate(std::size_t size,
704  read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
705  CompletionCondition, ReadHandler>* this_handler)
706  {
708  size, this_handler->handler_);
709  }
710 
711  template <typename AsyncRandomAccessReadDevice, typename Allocator,
712  typename CompletionCondition, typename ReadHandler>
713  inline void asio_handler_deallocate(void* pointer, std::size_t size,
714  read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
715  CompletionCondition, ReadHandler>* this_handler)
716  {
718  pointer, size, this_handler->handler_);
719  }
720 
721  template <typename AsyncRandomAccessReadDevice, typename Allocator,
722  typename CompletionCondition, typename ReadHandler>
724  read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
725  CompletionCondition, ReadHandler>* this_handler)
726  {
727  return this_handler->start_ == 0 ? true
729  this_handler->handler_);
730  }
731 
732  template <typename Function, typename AsyncRandomAccessReadDevice,
733  typename Allocator, typename CompletionCondition, typename ReadHandler>
734  inline void asio_handler_invoke(Function& function,
735  read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
736  CompletionCondition, ReadHandler>* this_handler)
737  {
739  function, this_handler->handler_);
740  }
741 
742  template <typename Function, typename AsyncRandomAccessReadDevice,
743  typename Allocator, typename CompletionCondition, typename ReadHandler>
744  inline void asio_handler_invoke(const Function& function,
745  read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
746  CompletionCondition, ReadHandler>* this_handler)
747  {
749  function, this_handler->handler_);
750  }
751 } // namespace detail
752 
753 template <typename AsyncRandomAccessReadDevice, typename Allocator,
754  typename CompletionCondition, typename ReadHandler>
755 inline ASIO_INITFN_RESULT_TYPE(ReadHandler,
756  void (asio::error_code, std::size_t))
757 async_read_at(AsyncRandomAccessReadDevice& d,
758  uint64_t offset, asio::basic_streambuf<Allocator>& b,
759  CompletionCondition completion_condition,
760  ASIO_MOVE_ARG(ReadHandler) handler)
761 {
762  // If you get an error on the following line it means that your handler does
763  // not meet the documented type requirements for a ReadHandler.
764  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
765 
767  ReadHandler, void (asio::error_code, std::size_t)> init(
768  ASIO_MOVE_CAST(ReadHandler)(handler));
769 
770  detail::read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
771  CompletionCondition, ASIO_HANDLER_TYPE(ReadHandler,
772  void (asio::error_code, std::size_t))>(
773  d, offset, b, completion_condition, init.handler)(
774  asio::error_code(), 0, 1);
775 
776  return init.result.get();
777 }
778 
779 template <typename AsyncRandomAccessReadDevice, typename Allocator,
780  typename ReadHandler>
781 inline ASIO_INITFN_RESULT_TYPE(ReadHandler,
782  void (asio::error_code, std::size_t))
783 async_read_at(AsyncRandomAccessReadDevice& d,
784  uint64_t offset, asio::basic_streambuf<Allocator>& b,
785  ASIO_MOVE_ARG(ReadHandler) handler)
786 {
787  // If you get an error on the following line it means that your handler does
788  // not meet the documented type requirements for a ReadHandler.
789  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
790 
792  ReadHandler, void (asio::error_code, std::size_t)> init(
793  ASIO_MOVE_CAST(ReadHandler)(handler));
794 
795  detail::read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
797  void (asio::error_code, std::size_t))>(
798  d, offset, b, transfer_all(), init.handler)(
799  asio::error_code(), 0, 1);
800 
801  return init.result.get();
802 }
803 
804 #endif // !defined(ASIO_NO_IOSTREAM)
805 
806 } // namespace asio
807 
809 
810 #endif // ASIO_IMPL_READ_AT_HPP
void asio_handler_deallocate(void *pointer, std::size_t size, binder1< Handler, Arg1 > *this_handler)
read_at_streambuf_op(AsyncRandomAccessReadDevice &device, uint64_t offset, basic_streambuf< Allocator > &streambuf, CompletionCondition completion_condition, ReadHandler &handler)
Definition: read_at.hpp:627
void throw_error(const asio::error_code &err)
Definition: throw_error.hpp:31
AsyncRandomAccessReadDevice & device_
Definition: read_at.hpp:225
std::size_t check_for_completion(const asio::error_code &ec, std::size_t total_transferred)
void * asio_handler_allocate(std::size_t size, binder1< Handler, Arg1 > *this_handler)
void operator()(const asio::error_code &ec, std::size_t bytes_transferred, int start=0)
Definition: read_at.hpp:200
asio::basic_streambuf< Allocator > MatchCondition enable_if< is_match_condition< MatchCondition >::value >::type *detail::async_result_init< ReadHandler, void(asio::error_code, std::size_t)> init(ASIO_MOVE_CAST(ReadHandler)(handler))
void operator()(const asio::error_code &ec, std::size_t bytes_transferred, int start=0)
Definition: read_at.hpp:358
#define ASIO_HANDLER_TYPE(h, sig)
mutable_buffers_type prepare(std::size_t n)
STL namespace.
AsyncRandomAccessReadDevice & device_
Definition: read_at.hpp:693
mutable_buffers_1 buffer(const mutable_buffer &b)
Create a new modifiable buffer from an existing buffer.
Definition: buffer.hpp:706
uint64_t offset
Definition: read_at.hpp:571
detail::transfer_all_t transfer_all()
asio::basic_streambuf< Allocator > & b
Definition: read.hpp:702
ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler, void(asio::error_code, Iterator)) async_connect(basic_socket< Protocol
std::size_t buffer_size(const mutable_buffer &b)
Get the number of bytes in a modifiable buffer.
Definition: buffer.hpp:357
void invoke(Function &function, Context &context)
std::size_t read_at(SyncRandomAccessReadDevice &d, uint64_t offset, const MutableBufferSequence &buffers, CompletionCondition completion_condition, asio::error_code &ec)
Definition: read_at.hpp:39
const MutableBufferSequence & buffers
Definition: read.hpp:521
void commit(std::size_t n)
Move characters from the output sequence to the input sequence.
#define ASIO_READ_HANDLER_CHECK(handler_type, handler)
Holds a buffer that can be modified.
Definition: buffer.hpp:91
read_at_op(AsyncRandomAccessReadDevice &device, uint64_t offset, const asio::mutable_buffers_1 &buffers, CompletionCondition completion_condition, ReadHandler &handler)
Definition: read_at.hpp:241
void asio_handler_invoke(Function &function, binder1< Handler, Arg1 > *this_handler)
asio::basic_streambuf< Allocator > CompletionCondition ASIO_MOVE_ARG(ReadHandler) handler)
Definition: read.hpp:704
void operator()(const asio::error_code &ec, std::size_t bytes_transferred, int start=0)
Definition: read_at.hpp:665
bool is_continuation(Context &context)
read_at_op(AsyncRandomAccessReadDevice &device, uint64_t offset, const MutableBufferSequence &buffers, CompletionCondition completion_condition, ReadHandler &handler)
Definition: read_at.hpp:162
read_at_op(AsyncRandomAccessReadDevice &device, uint64_t offset, const boost::array< Elem, 2 > &buffers, CompletionCondition completion_condition, ReadHandler &handler)
Definition: read_at.hpp:320
void operator()(const asio::error_code &ec, std::size_t bytes_transferred, int start=0)
Definition: read_at.hpp:279
Class to represent an error code value.
Definition: error_code.hpp:80
void deallocate(void *p, std::size_t s, Handler &h)
std::size_t read_size_helper(basic_streambuf< Allocator > &sb, std::size_t max_size)
std::size_t adapt_completion_condition_result(bool result)
Automatically resizable buffer class based on std::streambuf.
void * allocate(std::size_t s, Handler &h)
const MutableBufferSequence CompletionCondition completion_condition
Definition: read.hpp:521
handler_type< Handler, Signature >::type handler
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
async_result< typename handler_type< Handler, Signature >::type > result
std::size_t total_transferred_
Definition: read_at.hpp:230
asio::detail::consuming_buffers< mutable_buffer, MutableBufferSequence > buffers_
Definition: read_at.hpp:228
bool asio_handler_is_continuation(binder1< Handler, Arg1 > *this_handler)
read_at_op< AsyncRandomAccessReadDevice, MutableBufferSequence, CompletionCondition, ReadHandler > make_read_at_op(AsyncRandomAccessReadDevice &d, uint64_t offset, const MutableBufferSequence &buffers, CompletionCondition completion_condition, ReadHandler handler)
Definition: read_at.hpp:556
asio::basic_streambuf< Allocator > & streambuf_
Definition: read_at.hpp:695