Boost logo

Boost Users :

Subject: [Boost-users] async_read_some
From: Christer Borgqvist (christer.borgqvist10_at_[hidden])
Date: 2012-04-28 04:56:49


Hi,
Im playing around with the /boost_asio/example/http/server3
and using POST method.
The bytes_transferred is 231, but thats only the header and ends with
\r\n\r\n, need to read the rest.
Sometimes i get bytes_transferred to 1032, the right amount of data,
sometimes i get bytes_transferred = 231, but if i print the buffer_ i have
all the 1032 bytes.
Is it right that the bytes in the buffer_ and the bytes_transferred is not
the same?

appreciate any help.
/christer
void connection::handle_read(const boost::system::error_code& e,
    std::size_t bytes_transferred)
{
  if (!e)
  {
    boost::tribool result;
    boost::tie(result, boost::tuples::ignore) = request_parser_.parse(
        request_, buffer_.data(), buffer_.data() + bytes_transferred);

    if (result)
    {
      request_handler_.handle_request(request_, reply_);
      boost::asio::async_write(socket_, reply_.to_buffers(),
          strand_.wrap(
            boost::bind(&connection::handle_write, shared_from_this(),
              boost::asio::placeholders::error)));
    }
    else if (!result)
    {
      reply_ = reply::stock_reply(reply::bad_request);
      boost::asio::async_write(socket_, reply_.to_buffers(),
          strand_.wrap(
            boost::bind(&connection::handle_write, shared_from_this(),
              boost::asio::placeholders::error)));
    }
    else
    {
      socket_.async_read_some(boost::asio::buffer(buffer_),
          strand_.wrap(
            boost::bind(&connection::handle_read, shared_from_this(),
              boost::asio::placeholders::error,
              boost::asio::placeholders::bytes_transferred)));
    }
  }


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net