Пример #1
0
void AdminClient::read_handler(const boost::system::error_code& error, std::size_t bytes) {
    std::cout << "Recieved " << bytes << " bytes.\n";

    // The extra parens around the first argument here are necessary 
    // to avoid g++ interpreting this as a function declaration
    //std::string s((std::istreambuf_iterator<char>(&read_buffer_)), std::istreambuf_iterator<char>());

    if (error == boost::asio::error::eof)
        close();
    else if (error == boost::asio::error::operation_aborted)
        return;
    else if (error){
        std::cout << "Throwing an error.\n";
        throw boost::system::system_error(error); // Some other error.
    }

    std::string s(read_message_.data(bytes));
    std::cout << "Built string.\n";

    read_message_.consume(bytes);
    std::cout << read_message_.buffer().size() << " bytes remaining in buffer.\n";

    std::cout << s << "-----------------------\n";

    boost::system::error_code err;
    boost::asio::async_read_until(sock_, read_message_.buffer(), '\n', 
        boost::bind(&AdminClient::read_handler, this, 
            boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
}
Пример #2
0
        message(const message& msg) {
            const boost::asio::streambuf& sb(msg.buffer());

            boost::asio::streambuf::const_buffers_type data = sb.data();

            std::string s(boost::asio::buffers_begin(data), boost::asio::buffers_end(data));

            from_string(s.c_str(), s.length()); 
        }