2

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; 
flamemyst
  • 1,187
  • 7
  • 10
  • That's a good question. My first guess was that it would be unsafe too, but you can theorically read from a streambuf while something else writes at the end of it. – Tomaka17 Sep 01 '10 at 11:42
  • 2
    why do you want to manipulate the streambuf during an async_read operation? – Sam Miller Sep 01 '10 at 14:34
  • @sam nice question. remind me I can do async after consume all the incoming packet. the reason is for concurrency. now I think, it's not worth of it, I'll put processing before the next async read. – flamemyst Sep 03 '10 at 06:27
  • I can't find the statement that manipulating a `streambuf`while an async_write is working on the boost mailing list. Can you provide a link? – Alexandre Hamez Oct 12 '15 at 10:06

1 Answers1

1

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.

skimobear
  • 1,188
  • 10
  • 12