2
我知道在async_write工作時操縱streambuf並不安全,asio作者在boost郵件列表中聲明瞭這一點。我想知道的是,在async_read之後操縱streambuf是否安全?在boost :: asio :: 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;
這是一個很好的問題。我的第一個猜測是它也是不安全的,但是你可以從streambuf理論上讀取,而其他東西在其末尾寫入。 – Tomaka17 2010-09-01 11:42:19
爲什麼要在async_read操作期間操縱streambuf? – 2010-09-01 14:34:20
@sam很好的問題。提醒我我可以在使用所有傳入數據包之後進行異步處理。原因是併發。現在我認爲,這是不值得的,我會在下一次異步閱讀之前進行處理。 – flamemyst 2010-09-03 06:27:47