有时,boost http客户端异步读取响应得到错误代码5,消息为“需要缓冲区”,我找不到有关此错误代码的任何信息,此错误代码是什么意思?
void
do_read()
{
// Make the request empty before reading,
// otherwise the operation behavior is undefined.
std::shared_ptr<boost::beast::http::response<boost::beast::http::buffer_body>> p_read_remote_server_response = std::make_shared<boost::beast::http::response<boost::beast::http::buffer_body>>(); ;
std::shared_ptr<boost::beast::flat_buffer> p_read_remote_server_buffer = std::make_shared<boost::beast::flat_buffer>(15000000);
// Read a response
boost::beast::http::async_read(*pClientToServerStream, *p_read_remote_server_buffer, *p_read_remote_server_response,
boost::bind(&DCClient::on_read_remote_server,
shared_from_this(), p_read_remote_server_buffer, p_read_remote_server_response, _1, _2));
}
void
on_read_remote_server(
std::shared_ptr<boost::beast::flat_buffer> p_read_remote_server_buffer,
std::shared_ptr<boost::beast::http::response<boost::beast::http::buffer_body>> p_read_remote_server_response,
boost::beast::error_code ec,
std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);
std::stringstream strstm;
strstm.write((const char *)((*p_read_remote_server_buffer).data().data()), bytes_transferred);
std::string s = strstm.str();
// This means they closed the connection
if (ec == boost::beast::http::error::end_of_stream)
return do_close();
if (ec)
throw boost::system::system_error{ ec };
}
响应错误,方法on_read_remote_server参数bytes_transferred为124,我将响应转换为字符串,该字符串缺少http标头,仅正文:
std::stringstream strstm;
strstm.write((const char *)((*p_read_remote_server_buffer).data().data()), bytes_transferred);
std::string s = strstm.str();