Subject: [Boost-bugs] [Boost C++ Libraries] #12131: Boost Asio async HTTP Client example source code incorrect
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-04-16 08:03:45
#12131: Boost Asio async HTTP Client example source code incorrect
-----------------------------------------+---------------------------
Reporter: Micah Quinn <micah.quinn@â¦> | Owner: matias
Type: Bugs | Status: new
Milestone: To Be Determined | Component: Documentation
Version: Boost 1.61.0 | Severity: Problem
Keywords: |
-----------------------------------------+---------------------------
The example source code for the async HTTP Client
(http://www.boost.org/doc/libs/1_60_0/doc/html/boost_asio/example/cpp03/http/client/async_client.cpp)
does not output the final read bytes inside "handle_read_content" if the
parameter to the transfer_at_least(x) algorithm is greater than one. The
code prematurely checks for an error code and disregards any already read
data.
The current code in question:
{{{
void handle_read_content(const boost::system::error_code& err)
{
if (!err)
{
// Write all of the data that has been read so far.
std::cout << &response_;
// Continue reading remaining data until EOF.
boost::asio::async_read(socket_, response_,
boost::asio::transfer_at_least(1),
boost::bind(&client::handle_read_content, this,
boost::asio::placeholders::error));
}
else if (err != boost::asio::error::eof)
{
std::cout << "Error: " << err << "\n";
}
}
}}}
One possible "fix" for the code would be:
{{{
void handle_read_content(const boost::system::error_code& err)
{
// Write all of the data that has been read so far.
if ( response_.size() > 0 )
std::cout << &response_;
if (!err)
{
// Continue reading remaining data until EOF.
boost::asio::async_read(socket_, response_,
boost::asio::transfer_at_least(1024),
boost::bind(&client::handle_read_content, this,
boost::asio::placeholders::error));
}
else if (err != boost::asio::error::eof)
{
std::cout << "Error: " << err << "\n";
}
}
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/12131> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC