Boost C++ Libraries: Ticket #8464: boost::asio::read_size_helper non consistent with boost::asio::basic_streambuf::read_size_helper https://svn.boost.org/trac10/ticket/8464 <p> In boost 1.53.0 and svn trunk <a class="changeset" href="https://svn.boost.org/trac10/changeset/83967" title="Fix buffer size determination. Fixes #8082.">r83967</a> (current HEAD) in asio/basic_streambuf.hpp the function <em>read_size_helper</em> is defined two times: </p> <p> 1/ in <em>basic_streambuf</em> class l344: </p> <pre class="wiki"> // Helper function to get the preferred size for reading data. friend std::size_t read_size_helper( basic_streambuf&amp; sb, std::size_t max_size) { return std::min&lt;std::size_t&gt;( std::max&lt;std::size_t&gt;(512, sb.buffer_.capacity() - sb.size()), std::min&lt;std::size_t&gt;(max_size, sb.max_size() - sb.size())); } </pre><p> 2/ as a free function l356: </p> <pre class="wiki">// Helper function to get the preferred size for reading data. Used for any // user-provided specialisations of basic_streambuf. template &lt;typename Allocator&gt; inline std::size_t read_size_helper( basic_streambuf&lt;Allocator&gt;&amp; sb, std::size_t max_size) { return std::min&lt;std::size_t&gt;(512, std::min&lt;std::size_t&gt;(max_size, sb.max_size() - sb.size())); } </pre><p> They don't compute the same value: </p> <p> 1/ returns a number between 512 and max_size if max_size &gt; 512 (which happens in several locations in the code), otherwise returns max_size. </p> <p> 2/ returns at most 512. </p> <p> Shouldn't they return the same thing? It seems to me the intended result is 1/. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8464 Trac 1.4.3 chris_kohlhoff Fri, 24 May 2013 03:19:38 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/8464#comment:1 https://svn.boost.org/trac10/ticket/8464#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> The comment above the second version says it all: </p> <pre class="wiki">// Helper function to get the preferred size for reading data. Used for any // user-provided specialisations of basic_streambuf. </pre><p> The friend version uses knowledge of the internals to give a "better" result. Any user specialisations of basic_streambuf (which may or may not exist) may have a different implementation and so have to use a form based only on the public API. </p> Ticket