11 #ifndef ASIO_IMPL_READ_HPP 12 #define ASIO_IMPL_READ_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 37 template <
typename SyncReadStream,
typename MutableBufferSequence,
38 typename CompletionCondition>
39 std::size_t
read(SyncReadStream&
s,
const MutableBufferSequence&
buffers,
45 std::size_t total_transferred = 0;
48 while (tmp.begin() != tmp.end())
50 std::size_t bytes_transferred = s.read_some(tmp, ec);
51 tmp.consume(bytes_transferred);
52 total_transferred += bytes_transferred;
56 return total_transferred;
59 template <
typename SyncReadStream,
typename MutableBufferSequence>
60 inline std::size_t
read(SyncReadStream&
s,
const MutableBufferSequence&
buffers)
65 return bytes_transferred;
68 template <
typename SyncReadStream,
typename MutableBufferSequence>
69 inline std::size_t
read(SyncReadStream&
s,
const MutableBufferSequence&
buffers,
75 template <
typename SyncReadStream,
typename MutableBufferSequence,
76 typename CompletionCondition>
77 inline std::size_t
read(SyncReadStream&
s,
const MutableBufferSequence&
buffers,
81 std::size_t bytes_transferred =
read(s, buffers, completion_condition, ec);
83 return bytes_transferred;
86 #if !defined(ASIO_NO_IOSTREAM) 88 template <
typename SyncReadStream,
typename Allocator,
89 typename CompletionCondition>
90 std::size_t
read(SyncReadStream&
s,
95 std::size_t total_transferred = 0;
99 while (bytes_available > 0)
101 std::size_t bytes_transferred = s.read_some(b.
prepare(bytes_available), ec);
102 b.
commit(bytes_transferred);
103 total_transferred += bytes_transferred;
108 return total_transferred;
111 template <
typename SyncReadStream,
typename Allocator>
112 inline std::size_t
read(SyncReadStream&
s,
118 return bytes_transferred;
121 template <
typename SyncReadStream,
typename Allocator>
122 inline std::size_t
read(SyncReadStream&
s,
129 template <
typename SyncReadStream,
typename Allocator,
130 typename CompletionCondition>
131 inline std::size_t
read(SyncReadStream&
s,
136 std::size_t bytes_transferred =
read(s, b, completion_condition, ec);
138 return bytes_transferred;
141 #endif // !defined(ASIO_NO_IOSTREAM) 145 template <
typename AsyncReadStream,
typename MutableBufferSequence,
146 typename CompletionCondition,
typename ReadHandler>
154 CompletionCondition>(completion_condition),
163 #if defined(ASIO_HAS_MOVE) 183 #endif // defined(ASIO_HAS_MOVE) 186 std::size_t bytes_transferred,
int start = 0)
198 buffers_.consume(bytes_transferred);
200 if ((!ec && bytes_transferred == 0)
218 template <
typename AsyncReadStream,
219 typename CompletionCondition,
typename ReadHandler>
221 CompletionCondition, ReadHandler>
229 CompletionCondition>(completion_condition),
238 #if defined(ASIO_HAS_MOVE) 242 buffer_(other.buffer_),
252 buffer_(other.buffer_),
258 #endif // defined(ASIO_HAS_MOVE) 261 std::size_t bytes_transferred,
int start = 0)
275 if ((!ec && bytes_transferred == 0)
293 template <
typename AsyncReadStream,
typename Elem,
294 typename CompletionCondition,
typename ReadHandler>
296 CompletionCondition, ReadHandler>
303 CompletionCondition>(completion_condition),
312 #if defined(ASIO_HAS_MOVE) 332 #endif // defined(ASIO_HAS_MOVE) 335 std::size_t bytes_transferred,
int start = 0)
358 if ((!ec && bytes_transferred == 0)
376 #if defined(ASIO_HAS_STD_ARRAY) 378 template <
typename AsyncReadStream,
typename Elem,
379 typename CompletionCondition,
typename ReadHandler>
381 CompletionCondition, ReadHandler>
385 read_op(AsyncReadStream& stream,
const std::array<Elem, 2>&
buffers,
397 #if defined(ASIO_HAS_MOVE) 417 #endif // defined(ASIO_HAS_MOVE) 420 std::size_t bytes_transferred,
int start = 0)
423 std::array<asio::mutable_buffer, 2> >::type bufs = {{
443 if ((!ec && bytes_transferred == 0)
461 #endif // defined(ASIO_HAS_STD_ARRAY) 463 template <
typename AsyncReadStream,
typename MutableBufferSequence,
464 typename CompletionCondition,
typename ReadHandler>
466 read_op<AsyncReadStream, MutableBufferSequence,
467 CompletionCondition, ReadHandler>* this_handler)
470 size, this_handler->handler_);
473 template <
typename AsyncReadStream,
typename MutableBufferSequence,
474 typename CompletionCondition,
typename ReadHandler>
476 read_op<AsyncReadStream, MutableBufferSequence,
477 CompletionCondition, ReadHandler>* this_handler)
480 pointer, size, this_handler->handler_);
483 template <
typename AsyncReadStream,
typename MutableBufferSequence,
484 typename CompletionCondition,
typename ReadHandler>
486 read_op<AsyncReadStream, MutableBufferSequence,
487 CompletionCondition, ReadHandler>* this_handler)
489 return this_handler->start_ == 0 ?
true 491 this_handler->handler_);
494 template <
typename Function,
typename AsyncReadStream,
495 typename MutableBufferSequence,
typename CompletionCondition,
496 typename ReadHandler>
498 read_op<AsyncReadStream, MutableBufferSequence,
499 CompletionCondition, ReadHandler>* this_handler)
502 function, this_handler->handler_);
505 template <
typename Function,
typename AsyncReadStream,
506 typename MutableBufferSequence,
typename CompletionCondition,
507 typename ReadHandler>
509 read_op<AsyncReadStream, MutableBufferSequence,
510 CompletionCondition, ReadHandler>* this_handler)
513 function, this_handler->handler_);
517 template <
typename AsyncReadStream,
typename MutableBufferSequence,
518 typename CompletionCondition,
typename ReadHandler>
521 async_read(AsyncReadStream&
s, const MutableBufferSequence&
buffers,
542 template <
typename AsyncReadStream,
typename MutableBufferSequence,
543 typename ReadHandler>
546 async_read(AsyncReadStream&
s,
const MutableBufferSequence&
buffers,
566 #if !defined(ASIO_NO_IOSTREAM) 570 template <
typename AsyncReadStream,
typename Allocator,
571 typename CompletionCondition,
typename ReadHandler>
580 CompletionCondition>(completion_condition),
582 streambuf_(streambuf),
589 #if defined(ASIO_HAS_MOVE) 609 #endif // defined(ASIO_HAS_MOVE) 612 std::size_t bytes_transferred,
int start = 0)
614 std::size_t max_size, bytes_available;
622 stream_.async_read_some(streambuf_.prepare(bytes_available),
626 streambuf_.commit(bytes_transferred);
629 if ((!ec && bytes_transferred == 0) || bytes_available == 0)
645 template <
typename AsyncReadStream,
typename Allocator,
646 typename CompletionCondition,
typename ReadHandler>
649 CompletionCondition, ReadHandler>* this_handler)
652 size, this_handler->handler_);
655 template <
typename AsyncReadStream,
typename Allocator,
656 typename CompletionCondition,
typename ReadHandler>
659 CompletionCondition, ReadHandler>* this_handler)
662 pointer, size, this_handler->handler_);
665 template <
typename AsyncReadStream,
typename Allocator,
666 typename CompletionCondition,
typename ReadHandler>
669 CompletionCondition, ReadHandler>* this_handler)
671 return this_handler->start_ == 0 ?
true 673 this_handler->handler_);
676 template <
typename Function,
typename AsyncReadStream,
677 typename Allocator,
typename CompletionCondition,
typename ReadHandler>
680 CompletionCondition, ReadHandler>* this_handler)
683 function, this_handler->handler_);
686 template <
typename Function,
typename AsyncReadStream,
687 typename Allocator,
typename CompletionCondition,
typename ReadHandler>
690 CompletionCondition, ReadHandler>* this_handler)
693 function, this_handler->handler_);
697 template <
typename AsyncReadStream,
typename Allocator,
698 typename CompletionCondition,
typename ReadHandler>
701 async_read(AsyncReadStream&
s,
723 template <
typename AsyncReadStream,
typename Allocator,
typename ReadHandler>
726 async_read(AsyncReadStream&
s,
747 #endif // !defined(ASIO_NO_IOSTREAM) 753 #endif // ASIO_IMPL_READ_HPP
void asio_handler_deallocate(void *pointer, std::size_t size, binder1< Handler, Arg1 > *this_handler)
read_op(AsyncReadStream &stream, const boost::array< Elem, 2 > &buffers, CompletionCondition completion_condition, ReadHandler &handler)
asio::detail::consuming_buffers< mutable_buffer, MutableBufferSequence > buffers_
void throw_error(const asio::error_code &err)
std::size_t total_transferred_
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)
AsyncReadStream & stream_
read_op(AsyncReadStream &stream, const asio::mutable_buffers_1 &buffers, CompletionCondition completion_condition, ReadHandler &handler)
AsyncReadStream & stream_
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))
#define ASIO_HANDLER_TYPE(h, sig)
mutable_buffers_type prepare(std::size_t n)
mutable_buffers_1 buffer(const mutable_buffer &b)
Create a new modifiable buffer from an existing buffer.
asio::basic_streambuf< Allocator > & streambuf_
detail::transfer_all_t transfer_all()
asio::basic_streambuf< Allocator > & b
std::size_t total_transferred_
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)
asio::mutable_buffer buffer_
const MutableBufferSequence & buffers
void commit(std::size_t n)
Move characters from the output sequence to the input sequence.
AsyncReadStream & stream_
#define ASIO_READ_HANDLER_CHECK(handler_type, handler)
std::size_t total_transferred_
read_op(AsyncReadStream &stream, const MutableBufferSequence &buffers, CompletionCondition completion_condition, ReadHandler &handler)
Holds a buffer that can be modified.
void operator()(const asio::error_code &ec, std::size_t bytes_transferred, int start=0)
void operator()(const asio::error_code &ec, std::size_t bytes_transferred, int start=0)
AsyncReadStream & stream_
void asio_handler_invoke(Function &function, binder1< Handler, Arg1 > *this_handler)
asio::basic_streambuf< Allocator > CompletionCondition ASIO_MOVE_ARG(ReadHandler) handler)
bool is_continuation(Context &context)
void operator()(const asio::error_code &ec, std::size_t bytes_transferred, int start=0)
std::size_t read(SyncReadStream &s, const MutableBufferSequence &buffers, CompletionCondition completion_condition, asio::error_code &ec)
Attempt to read a certain amount of data from a stream before returning.
Class to represent an error code value.
boost::array< Elem, 2 > buffers_
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_
void * allocate(std::size_t s, Handler &h)
const MutableBufferSequence CompletionCondition completion_condition
handler_type< Handler, Signature >::type handler
read_streambuf_op(AsyncReadStream &stream, basic_streambuf< Allocator > &streambuf, CompletionCondition completion_condition, ReadHandler &handler)
#define ASIO_MOVE_CAST(type)
async_result< typename handler_type< Handler, Signature >::type > result
void operator()(const asio::error_code &ec, std::size_t bytes_transferred, int start=0)
bool asio_handler_is_continuation(binder1< Handler, Arg1 > *this_handler)