11 #ifndef ASIO_IMPL_READ_AT_HPP 12 #define ASIO_IMPL_READ_AT_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 37 template <
typename SyncRandomAccessReadDevice,
typename MutableBufferSequence,
38 typename CompletionCondition>
39 std::size_t
read_at(SyncRandomAccessReadDevice& d,
46 std::size_t total_transferred = 0;
49 while (tmp.begin() != tmp.end())
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;
58 return total_transferred;
61 template <
typename SyncRandomAccessReadDevice,
typename MutableBufferSequence>
62 inline std::size_t
read_at(SyncRandomAccessReadDevice& d,
66 std::size_t bytes_transferred =
read_at(
69 return bytes_transferred;
72 template <
typename SyncRandomAccessReadDevice,
typename MutableBufferSequence>
73 inline std::size_t
read_at(SyncRandomAccessReadDevice& d,
80 template <
typename SyncRandomAccessReadDevice,
typename MutableBufferSequence,
81 typename CompletionCondition>
82 inline std::size_t
read_at(SyncRandomAccessReadDevice& d,
87 std::size_t bytes_transferred =
read_at(
88 d, offset, buffers, completion_condition, ec);
90 return bytes_transferred;
93 #if !defined(ASIO_NO_IOSTREAM) 95 template <
typename SyncRandomAccessReadDevice,
typename Allocator,
96 typename CompletionCondition>
97 std::size_t
read_at(SyncRandomAccessReadDevice& d,
102 std::size_t total_transferred = 0;
106 while (bytes_available > 0)
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;
116 return total_transferred;
119 template <
typename SyncRandomAccessReadDevice,
typename Allocator>
120 inline std::size_t
read_at(SyncRandomAccessReadDevice& d,
124 std::size_t bytes_transferred =
read_at(
127 return bytes_transferred;
130 template <
typename SyncRandomAccessReadDevice,
typename Allocator>
131 inline std::size_t
read_at(SyncRandomAccessReadDevice& d,
138 template <
typename SyncRandomAccessReadDevice,
typename Allocator,
139 typename CompletionCondition>
140 inline std::size_t
read_at(SyncRandomAccessReadDevice& d,
145 std::size_t bytes_transferred =
read_at(
146 d, offset, b, completion_condition, ec);
148 return bytes_transferred;
151 #endif // !defined(ASIO_NO_IOSTREAM) 155 template <
typename AsyncRandomAccessReadDevice,
156 typename MutableBufferSequence,
typename CompletionCondition,
157 typename ReadHandler>
166 CompletionCondition>(completion_condition),
176 #if defined(ASIO_HAS_MOVE) 198 #endif // defined(ASIO_HAS_MOVE) 201 std::size_t bytes_transferred,
int start = 0)
213 buffers_.consume(bytes_transferred);
215 if ((!ec && bytes_transferred == 0)
234 template <
typename AsyncRandomAccessReadDevice,
235 typename CompletionCondition,
typename ReadHandler>
245 CompletionCondition>(completion_condition),
255 #if defined(ASIO_HAS_MOVE) 260 buffer_(other.buffer_),
271 buffer_(other.buffer_),
277 #endif // defined(ASIO_HAS_MOVE) 280 std::size_t bytes_transferred,
int start = 0)
294 if ((!ec && bytes_transferred == 0)
313 template <
typename AsyncRandomAccessReadDevice,
typename Elem,
314 typename CompletionCondition,
typename ReadHandler>
316 CompletionCondition, ReadHandler>
324 CompletionCondition>(completion_condition),
334 #if defined(ASIO_HAS_MOVE) 356 #endif // defined(ASIO_HAS_MOVE) 359 std::size_t bytes_transferred,
int start = 0)
383 if ((!ec && bytes_transferred == 0)
402 #if defined(ASIO_HAS_STD_ARRAY) 404 template <
typename AsyncRandomAccessReadDevice,
typename Elem,
405 typename CompletionCondition,
typename ReadHandler>
407 CompletionCondition, ReadHandler>
411 read_at_op(AsyncRandomAccessReadDevice& device,
425 #if defined(ASIO_HAS_MOVE) 447 #endif // defined(ASIO_HAS_MOVE) 450 std::size_t bytes_transferred,
int start = 0)
453 std::array<asio::mutable_buffer, 2> >::type bufs = {{
474 if ((!ec && bytes_transferred == 0)
485 AsyncRandomAccessReadDevice&
device_;
493 #endif // defined(ASIO_HAS_STD_ARRAY) 495 template <
typename AsyncRandomAccessReadDevice,
496 typename MutableBufferSequence,
typename CompletionCondition,
497 typename ReadHandler>
499 read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
500 CompletionCondition, ReadHandler>* this_handler)
503 size, this_handler->handler_);
506 template <
typename AsyncRandomAccessReadDevice,
507 typename MutableBufferSequence,
typename CompletionCondition,
508 typename ReadHandler>
510 read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
511 CompletionCondition, ReadHandler>* this_handler)
514 pointer, size, this_handler->handler_);
517 template <
typename AsyncRandomAccessReadDevice,
518 typename MutableBufferSequence,
typename CompletionCondition,
519 typename ReadHandler>
521 read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
522 CompletionCondition, ReadHandler>* this_handler)
524 return this_handler->start_ == 0 ?
true 526 this_handler->handler_);
529 template <
typename Function,
typename AsyncRandomAccessReadDevice,
530 typename MutableBufferSequence,
typename CompletionCondition,
531 typename ReadHandler>
533 read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
534 CompletionCondition, ReadHandler>* this_handler)
537 function, this_handler->handler_);
540 template <
typename Function,
typename AsyncRandomAccessReadDevice,
541 typename MutableBufferSequence,
typename CompletionCondition,
542 typename ReadHandler>
544 read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
545 CompletionCondition, ReadHandler>* this_handler)
548 function, this_handler->handler_);
551 template <
typename AsyncRandomAccessReadDevice,
552 typename MutableBufferSequence,
typename CompletionCondition,
553 typename ReadHandler>
554 inline read_at_op<AsyncRandomAccessReadDevice,
555 MutableBufferSequence, CompletionCondition, ReadHandler>
560 return read_at_op<AsyncRandomAccessReadDevice,
561 MutableBufferSequence, CompletionCondition, ReadHandler>(
566 template <
typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence,
567 typename CompletionCondition,
typename ReadHandler>
570 async_read_at(AsyncRandomAccessReadDevice& d,
592 template <
typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence,
593 typename ReadHandler>
596 async_read_at(AsyncRandomAccessReadDevice& d,
597 uint64_t offset,
const MutableBufferSequence& buffers,
617 #if !defined(ASIO_NO_IOSTREAM) 621 template <
typename AsyncRandomAccessReadDevice,
typename Allocator,
622 typename CompletionCondition,
typename ReadHandler>
629 CompletionCondition completion_condition, ReadHandler& handler)
631 CompletionCondition>(completion_condition),
634 streambuf_(streambuf),
641 #if defined(ASIO_HAS_MOVE) 663 #endif // defined(ASIO_HAS_MOVE) 666 std::size_t bytes_transferred,
int start = 0)
668 std::size_t max_size, bytes_available;
677 streambuf_.prepare(bytes_available),
681 streambuf_.commit(bytes_transferred);
684 if ((!ec && bytes_transferred == 0) || bytes_available == 0)
701 template <
typename AsyncRandomAccessReadDevice,
typename Allocator,
702 typename CompletionCondition,
typename ReadHandler>
705 CompletionCondition, ReadHandler>* this_handler)
708 size, this_handler->handler_);
711 template <
typename AsyncRandomAccessReadDevice,
typename Allocator,
712 typename CompletionCondition,
typename ReadHandler>
715 CompletionCondition, ReadHandler>* this_handler)
718 pointer, size, this_handler->handler_);
721 template <
typename AsyncRandomAccessReadDevice,
typename Allocator,
722 typename CompletionCondition,
typename ReadHandler>
725 CompletionCondition, ReadHandler>* this_handler)
727 return this_handler->start_ == 0 ?
true 729 this_handler->handler_);
732 template <
typename Function,
typename AsyncRandomAccessReadDevice,
733 typename Allocator,
typename CompletionCondition,
typename ReadHandler>
736 CompletionCondition, ReadHandler>* this_handler)
739 function, this_handler->handler_);
742 template <
typename Function,
typename AsyncRandomAccessReadDevice,
743 typename Allocator,
typename CompletionCondition,
typename ReadHandler>
746 CompletionCondition, ReadHandler>* this_handler)
749 function, this_handler->handler_);
753 template <
typename AsyncRandomAccessReadDevice,
typename Allocator,
754 typename CompletionCondition,
typename ReadHandler>
757 async_read_at(AsyncRandomAccessReadDevice& d,
759 CompletionCondition completion_condition,
779 template <
typename AsyncRandomAccessReadDevice,
typename Allocator,
780 typename ReadHandler>
783 async_read_at(AsyncRandomAccessReadDevice& d,
804 #endif // !defined(ASIO_NO_IOSTREAM) 810 #endif // ASIO_IMPL_READ_AT_HPP
AsyncRandomAccessReadDevice & device_
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)
void throw_error(const asio::error_code &err)
AsyncRandomAccessReadDevice & device_
AsyncRandomAccessReadDevice & device_
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)
std::size_t total_transferred_
void operator()(const asio::error_code &ec, std::size_t bytes_transferred, int start=0)
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)
#define ASIO_HANDLER_TYPE(h, sig)
mutable_buffers_type prepare(std::size_t n)
AsyncRandomAccessReadDevice & device_
mutable_buffers_1 buffer(const mutable_buffer &b)
Create a new modifiable buffer from an existing buffer.
detail::transfer_all_t transfer_all()
asio::basic_streambuf< Allocator > & b
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.
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)
const MutableBufferSequence & buffers
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.
read_at_op(AsyncRandomAccessReadDevice &device, uint64_t offset, const asio::mutable_buffers_1 &buffers, CompletionCondition completion_condition, ReadHandler &handler)
void asio_handler_invoke(Function &function, binder1< Handler, Arg1 > *this_handler)
asio::basic_streambuf< Allocator > CompletionCondition ASIO_MOVE_ARG(ReadHandler) handler)
void operator()(const asio::error_code &ec, std::size_t bytes_transferred, int start=0)
bool is_continuation(Context &context)
read_at_op(AsyncRandomAccessReadDevice &device, uint64_t offset, const MutableBufferSequence &buffers, CompletionCondition completion_condition, ReadHandler &handler)
read_at_op(AsyncRandomAccessReadDevice &device, uint64_t offset, const boost::array< Elem, 2 > &buffers, CompletionCondition completion_condition, ReadHandler &handler)
void operator()(const asio::error_code &ec, std::size_t bytes_transferred, int start=0)
Class to represent an error code value.
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.
std::size_t total_transferred_
std::size_t total_transferred_
void * allocate(std::size_t s, Handler &h)
const MutableBufferSequence CompletionCondition completion_condition
handler_type< Handler, Signature >::type handler
#define ASIO_MOVE_CAST(type)
async_result< typename handler_type< Handler, Signature >::type > result
std::size_t total_transferred_
asio::detail::consuming_buffers< mutable_buffer, MutableBufferSequence > buffers_
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)
asio::mutable_buffer buffer_
boost::array< Elem, 2 > buffers_
asio::basic_streambuf< Allocator > & streambuf_