By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,375 Members | 1,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,375 IT Pros & Developers. It's quick & easy.

Stringbuf for concurrent writing And reading

P: 5
Hi all,

I want to use a single std::stringbuf for writing (by a std::ostream)
and for reading (by a std::istream), concurrently in two threads.
This came to my mind, because the code for reading should be as with any other istream and cannot be changed.

Now my problem is, that a do not get any data in the reading loop
std::ofstream tempfile("test.pdf",
std::ios_base::out | std::ios_base::trunc | std::ios_base::binary);
while (!is->eof()) {
is->read(buffer, bufferSize);
tempfile.write(buffer, is->gcount());

The writing thread proceeds as expected and finally finishes writing.

Any hints? What are my misconceptions?

Nov 22 '06 #1
Share this Question
Share on Google+
3 Replies

P: 24
How did you define 'is'?
Nov 22 '06 #2

P: 5
How did you define 'is'?
is is an istream* managed by a boost::shared_ptr
Expand|Select|Wrap|Line Numbers
  1. typedef boost::shared_ptr<std::istream> IStreamP;
  2. IStreamP is = data->getIStream();
The istream is created with the same std::stringbuf used during writing (in a ostream of course!).
It seems that I do not get any content during reading or the read pointer is always at the end or ..
Nov 22 '06 #3

P: 5
Hi again,

let me put it differently. I just tested, that it does not depend on
If I write to the stringbuf in a std:: ostream (or a std::iostream) and
then try to read
with a std::istream* is (or the same std::iostream* is), it does not
work either.
I immediatly get, (is->fail() == true) :-(
Also tried is->seekg(0); with the same result.

Does anybody have an example showing usage of stringbuf with
std:: ostream and std::istream?
Or can somebody give some details on the internals, when
(is->fail()==true) and (is->eof()==true) does occur?

Thanks very much,
Nov 23 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.