Question

There's example HTTP Client at http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/example/http/client/async_client.cpp Please help me to change maximum buffer size like explained in following code (it's from examples downloaded with library, not from site):

void handle_write_request(const boost::system::error_code& err)
{
  if (!err)
  {
    // Read the response status line. The response_ streambuf will
    // automatically grow to accommodate the entire line. The growth may be
    // limited by <b>passing a maximum size to the streambuf constructor</b>.
    boost::asio::async_read_until(socket_, response_, "\r\n",
        boost::bind(&client::handle_read_status_line, this,
          boost::asio::placeholders::error));
  }
  else
  {
    std::cout << "Error: " << err.message() << "\n";
  }
}

And here's the constructor of response buffer:

boost::asio::streambuf response_;

But compiler says that following code is invalid:

boost::asio::streambuf response_(1024);

It seems that default buffer is 512 bytes sized, I need larger size.

Was it helpful?

Solution

1) I'm not sure where your 512 bytes limit is coming from since the constructor for the asio::basic_streambuf has the following signature (which allows it to store way more than 512 or 1024 bytes):

explicit basic_streambuf(
    std::size_t max_size = (std::numeric_limits<std::size_t>::max)(),
    const Allocator& allocator = Allocator())

2) This code boost::asio::streambuf response_(1024); is invalid since you cannot initialize member variables at declaration point, you must do it in the constructor's initializer list or it's body. If you don't it will be default initialized.

3) The comment in the code referrers to limiting/restricting the maximum size of the streambuf - so it will definitely not help you get "a larger size", on the contrary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top