samedi 27 juin 2015

Boost ASIO SSL get the number of available bytes for read

From this example, the size of the buffer available for reading is 1024 bytes. However, in the boost::asio::buffer() of handle_write(), I can't put that number. The program would give an error:

Write failed: uninitialized

The program would only work if I put exactly the number of bytes sent from the server.

So I tried to use the function available() which I found defined in the include file basic_socket.hpp to tell the number of available bytes to read, but I'm not sure how to call this function. Please assist!

void handle_write(const boost::system::error_code& error, size_t bytes_transferred)
{
    if (!error)
    {
        size_t len = socket_.available();
        boost::asio::async_read(socket_,
                                boost::asio::buffer(reply_, len),
                                boost::bind(&SSLClient::handle_read, this,
                                            boost::asio::placeholders::error,
                                            boost::asio::placeholders::bytes_transferred));
    }
    else
    {
        std::cout << "Write failed: " << error.message() << "\n";
    }
}

The question is: In this example, how can I read all the bytes available?

Aucun commentaire:

Enregistrer un commentaire