boost.asio - 设置最大读取流大小
http 中有示例 HTTP 客户端: //www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/example/http/client/async_client.cpp 请帮助我更改最大缓冲区大小,如以下代码中所述(它来自随库下载的示例,而不是从站点):
void handle_write_request(const boost::system::error_code& err)
{
if (!err)
{
// Read the response status line. The response_ streambuf will
// automatically grow to accommodate the entire line. The growth may be
// limited by <b>passing a maximum size to the streambuf constructor</b>.
boost::asio::async_read_until(socket_, response_, "\r\n",
boost::bind(&client::handle_read_status_line, this,
boost::asio::placeholders::error));
}
else
{
std::cout << "Error: " << err.message() << "\n";
}
}
这是响应缓冲区的构造函数:
boost::asio::streambuf response_;
但编译器表示以下代码无效:
boost::asio::streambuf response_(
1024
);
看来默认缓冲区是512
字节大小,我需要更大的大小。
There's example HTTP Client at http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/example/http/client/async_client.cpp
Please help me to change maximum buffer size like explained in following code (it's from examples downloaded with library, not from site):
void handle_write_request(const boost::system::error_code& err)
{
if (!err)
{
// Read the response status line. The response_ streambuf will
// automatically grow to accommodate the entire line. The growth may be
// limited by <b>passing a maximum size to the streambuf constructor</b>.
boost::asio::async_read_until(socket_, response_, "\r\n",
boost::bind(&client::handle_read_status_line, this,
boost::asio::placeholders::error));
}
else
{
std::cout << "Error: " << err.message() << "\n";
}
}
And here's the constructor of response buffer:
boost::asio::streambuf response_;
But compiler says that following code is invalid:
boost::asio::streambuf response_(
1024
);
It seems that default buffer is 512
bytes sized, I need larger size.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1)我不确定您的 512 字节限制来自哪里,因为
asio::basic_streambuf
的构造函数具有以下签名(这允许它存储超过 512 或 1024 字节的方式):2) 此代码
boost::asio::streambuf response_(1024);
无效,因为您无法在声明点初始化成员变量,您必须在构造函数的初始值设定项列表或其主体中执行此操作。如果不这样做,它将被默认初始化。3)代码中的注释引用了限制/限制
streambuf
的最大大小 - 所以它绝对不会帮助你获得“更大的大小”,相反。1) I'm not sure where your 512 bytes limit is coming from since the constructor for the
asio::basic_streambuf
has the following signature (which allows it to store way more than 512 or 1024 bytes):2) This code
boost::asio::streambuf response_(1024);
is invalid since you cannot initialize member variables at declaration point, you must do it in the constructor's initializer list or it's body. If you don't it will be default initialized.3) The comment in the code referrers to limiting/restricting the maximum size of the
streambuf
- so it will definitely not help you get "a larger size", on the contrary.