执行 boost::asio::async_read 后操作 Streambuf 是否安全?
我知道在 async_write 按照 asio 作者在 boost 邮件列表上所述工作时操作 Streambuf 是不安全的。我想知道的是,在async_read之后操作streambuf是否安全?
例子:
async_read(socket_, recv_streambuf_, ...);
// manipulated while async_read is working
// for example, after I call async_read,
recv_streambuf_.consume(2);
// or something advance, like this...
int var;
std::istream recv_is(recv_streambuf_);
recv_is >> var;
I know it's not safe to manipulated streambuf while async_write working as stated by asio author on boost mailing list. What I want to know is, is it safe to manipulated streambuf after async_read?
Example:
async_read(socket_, recv_streambuf_, ...);
// manipulated while async_read is working
// for example, after I call async_read,
recv_streambuf_.consume(2);
// or something advance, like this...
int var;
std::istream recv_is(recv_streambuf_);
recv_is >> var;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当执行 async_read 回调时,您应该能够对 Streambuf 执行任何操作。回调让我们知道 asio 何时完成使用内存。
You should be able to do whatever you like with the streambuf when your async_read callback is executed. The callback lets us know when asio is finished using the memory.