Opened 10 years ago

Closed 9 years ago

#8464 closed Bugs (invalid)

boost::asio::read_size_helper non consistent with boost::asio::basic_streambuf::read_size_helper

Reported by: Thomas Riccardi <riccardi@…> Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

In boost 1.53.0 and svn trunk r83967 (current HEAD) in asio/basic_streambuf.hpp the function read_size_helper is defined two times:

1/ in basic_streambuf class l344:

  // Helper function to get the preferred size for reading data.
  friend std::size_t read_size_helper(
      basic_streambuf& sb, std::size_t max_size)
  {
    return std::min<std::size_t>(
        std::max<std::size_t>(512, sb.buffer_.capacity() - sb.size()),
        std::min<std::size_t>(max_size, sb.max_size() - sb.size()));
  }

2/ as a free function l356:

// Helper function to get the preferred size for reading data. Used for any
// user-provided specialisations of basic_streambuf.
template <typename Allocator>
inline std::size_t read_size_helper(
    basic_streambuf<Allocator>& sb, std::size_t max_size)
{
  return std::min<std::size_t>(512,
      std::min<std::size_t>(max_size, sb.max_size() - sb.size()));
}

They don't compute the same value:

1/ returns a number between 512 and max_size if max_size > 512 (which happens in several locations in the code), otherwise returns max_size.

2/ returns at most 512.

Shouldn't they return the same thing? It seems to me the intended result is 1/.

Change History (1)

comment:1 by chris_kohlhoff, 9 years ago

Resolution: invalid
Status: newclosed

The comment above the second version says it all:

// Helper function to get the preferred size for reading data. Used for any
// user-provided specialisations of basic_streambuf.

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.

Note: See TracTickets for help on using tickets.