1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>read (2 of 16 overloads)</title> 5<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../boost_asio.html" title="Boost.Asio"> 8<link rel="up" href="../read.html" title="read"> 9<link rel="prev" href="overload1.html" title="read (1 of 16 overloads)"> 10<link rel="next" href="overload3.html" title="read (3 of 16 overloads)"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="overload1.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../read.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../boost_asio.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="overload3.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h4 class="title"> 27<a name="boost_asio.reference.read.overload2"></a><a class="link" href="overload2.html" title="read (2 of 16 overloads)">read (2 of 16 28 overloads)</a> 29</h4></div></div></div> 30<p> 31 Attempt to read a certain amount of data from a stream before returning. 32 </p> 33<pre class="programlisting">template< 34 typename <a class="link" href="../SyncReadStream.html" title="Buffer-oriented synchronous read stream requirements">SyncReadStream</a>, 35 typename <a class="link" href="../MutableBufferSequence.html" title="Mutable buffer sequence requirements">MutableBufferSequence</a>> 36std::size_t read( 37 SyncReadStream & s, 38 const MutableBufferSequence & buffers, 39 boost::system::error_code & ec, 40 typename enable_if< is_mutable_buffer_sequence< MutableBufferSequence >::value >::type * = 0); 41</pre> 42<p> 43 This function is used to read a certain number of bytes of data from a 44 stream. The call will block until one of the following conditions is true: 45 </p> 46<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 47<li class="listitem"> 48 The supplied buffers are full. That is, the bytes transferred is equal 49 to the sum of the buffer sizes. 50 </li> 51<li class="listitem"> 52 An error occurred. 53 </li> 54</ul></div> 55<p> 56 This operation is implemented in terms of zero or more calls to the stream's 57 read_some function. 58 </p> 59<h6> 60<a name="boost_asio.reference.read.overload2.h0"></a> 61 <span class="phrase"><a name="boost_asio.reference.read.overload2.parameters"></a></span><a class="link" href="overload2.html#boost_asio.reference.read.overload2.parameters">Parameters</a> 62 </h6> 63<div class="variablelist"> 64<p class="title"><b></b></p> 65<dl class="variablelist"> 66<dt><span class="term">s</span></dt> 67<dd><p> 68 The stream from which the data is to be read. The type must support 69 the SyncReadStream concept. 70 </p></dd> 71<dt><span class="term">buffers</span></dt> 72<dd><p> 73 One or more buffers into which the data will be read. The sum of 74 the buffer sizes indicates the maximum number of bytes to read from 75 the stream. 76 </p></dd> 77<dt><span class="term">ec</span></dt> 78<dd><p> 79 Set to indicate what error occurred, if any. 80 </p></dd> 81</dl> 82</div> 83<h6> 84<a name="boost_asio.reference.read.overload2.h1"></a> 85 <span class="phrase"><a name="boost_asio.reference.read.overload2.return_value"></a></span><a class="link" href="overload2.html#boost_asio.reference.read.overload2.return_value">Return 86 Value</a> 87 </h6> 88<p> 89 The number of bytes transferred. 90 </p> 91<h6> 92<a name="boost_asio.reference.read.overload2.h2"></a> 93 <span class="phrase"><a name="boost_asio.reference.read.overload2.example"></a></span><a class="link" href="overload2.html#boost_asio.reference.read.overload2.example">Example</a> 94 </h6> 95<p> 96 To read into a single data buffer use the <a class="link" href="../buffer.html" title="buffer"><code class="computeroutput">buffer</code></a> 97 function as follows: 98 </p> 99<pre class="programlisting">boost::asio::read(s, boost::asio::buffer(data, size), ec); 100</pre> 101<p> 102 See the <a class="link" href="../buffer.html" title="buffer"><code class="computeroutput">buffer</code></a> 103 documentation for information on reading into multiple buffers in one go, 104 and how to use it with arrays, boost::array or std::vector. 105 </p> 106<h6> 107<a name="boost_asio.reference.read.overload2.h3"></a> 108 <span class="phrase"><a name="boost_asio.reference.read.overload2.remarks"></a></span><a class="link" href="overload2.html#boost_asio.reference.read.overload2.remarks">Remarks</a> 109 </h6> 110<p> 111 This overload is equivalent to calling: 112 </p> 113<pre class="programlisting">boost::asio::read( 114 s, buffers, 115 boost::asio::transfer_all(), ec); 116</pre> 117</div> 118<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 119<td align="left"></td> 120<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M. 121 Kohlhoff<p> 122 Distributed under the Boost Software License, Version 1.0. (See accompanying 123 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 124 </p> 125</div></td> 126</tr></table> 127<hr> 128<div class="spirit-nav"> 129<a accesskey="p" href="overload1.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../read.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../boost_asio.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="overload3.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> 130</div> 131</body> 132</html> 133