执行 boost::asio::async_read 后操作 Streambuf 是否安全?

发布于 2024-09-16 19:43:05 字数 410 浏览 4 评论 0原文

我知道在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅此而已 2024-09-23 19:43:05

当执行 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文