[iostreams] Flushing problems with :filtering_ostream
I had some older code which used to work before, but seem to have
flushing problems now.
The problem is I can not make boost::iostreams::filtering_ostream
flush properly. Here is a snippet of my code, which is not compilable
in the current form, since I just pulled it out of my own code. Here
it goes :
/* Helper class for writing gzipped files */
class gzip_sink
{
public:
typedef char char_type;
typedef boost::iostreams::sink_tag category;
Log &Logger_; /* Logger */
boost::iostreams::filtering_ostream sink_; /* Sink used
to push filters */
SlmOfstream outifstr_; /* Write
stream to be pushed into sink */
std::wstring name_; /* Store name
of attached file */
/* Constructor */
gzip_sink(const wchar_t *filename,Log &logger)
SlmExcStartConstructor :
Logger_(logger),
name_(filename)
{
/* Open for write */
SlmOpenWriteFile(Logger_,
name_.c_str(),
outifstr_);
/* Push gzip compressor */
sink_.push(boost::iostreams::gzip_compressor());
}
SlmExcStopConstructor
gzip_sink(const gzip_sink &rhs)
SlmExcStartConstructor :
Logger_(rhs.Logger_),
name_(rhs.name_)
{
/* Open for write */
SlmOpenWriteFile(Logger_,
name_.c_str(),
outifstr_);
/* Push gzip compressor */
sink_.push(boost::iostreams::gzip_compressor());
}
SlmExcStopConstructor
void Close()
{
sink_.reset();
}
~gzip_sink()
{
sink_.reset();
}
/* Write function */
std::streamsize write( const char * s, std::streamsize n )
{
/* Push write stream */
/* THIS IS THE HACK !!! WE NEED TO PUSH AND POP EACH TIME
OTHERWISE SOME FLUSH IS NOT DONE!! */
sink_.push(outifstr_);
sink_.write(s,n);
sink_.pop();
return n;
}
};
I have to push and pop the stream on to the sink each time I write,
which should only be done once in the constructor. It is clearly some
flushing issue, but I have tried flushing in all places and no luck,
any help ?
If you think it looks a bit odd, it's because I use it together with
boost::iostreams::code_converter
On 4/18/2011 8:31 AM, Bo Jensen wrote:
I had some older code which used to work before, but seem to have flushing problems now.
What version of Boost are you using? The reason I ask is because there was a "flushing a filtering_ostream" bug which was fixed in Boost 1.46. For details see: https://svn.boost.org/trac/boost/ticket/4590
On Fri, Apr 22, 2011 at 4:47 PM, eg
On 4/18/2011 8:31 AM, Bo Jensen wrote:
I had some older code which used to work before, but seem to have flushing problems now.
What version of Boost are you using?
The reason I ask is because there was a "flushing a filtering_ostream" bug which was fixed in Boost 1.46.
For details see: https://svn.boost.org/trac/boost/ticket/4590
Thanks for the reply. I am currently investigating if some of the issues mentioned in the thread is effecting my code. I am using boost 1.46.1, but the bug is not fixed ! I downloaded and ran the first test case and it failed still.
On 4/22/2011 12:00 PM, Bo Jensen wrote:
What version of Boost are you using?
The reason I ask is because there was a "flushing a filtering_ostream" bug which was fixed in Boost 1.46.
For details see: https://svn.boost.org/trac/boost/ticket/4590
Thanks for the reply. I am currently investigating if some of the issues mentioned in the thread is effecting my code.
I am using boost 1.46.1, but the bug is not fixed ! I downloaded and ran the first test case and it failed still.
Looking at the ticket, it refers to the changeset that was committed. A new test case was added to the sources in the file: "test_filtering_ostream_flush.hpp" Specifically, you should be able to see this in: boost_1_46_1\libs\iostreams\test\filtering_stream_flush_test.hpp If you run these tests on your computer, do they pass? (You should be able to run bjam from the test directory). If so, how does this official test case differ from your own problem? Also, there is another variation of a flush issue referenced in the ticket at: https://svn.boost.org/trac/boost/ticket/4728
On Fri, Apr 22, 2011 at 10:55 PM, eg
On 4/22/2011 12:00 PM, Bo Jensen wrote:
What version of Boost are you using?
The reason I ask is because there was a "flushing a filtering_ostream" bug which was fixed in Boost 1.46.
For details see: https://svn.boost.org/trac/boost/ticket/4590
Thanks for the reply. I am currently investigating if some of the issues mentioned in the thread is effecting my code.
I am using boost 1.46.1, but the bug is not fixed ! I downloaded and ran the first test case and it failed still.
Looking at the ticket, it refers to the changeset that was committed. A new test case was added to the sources in the file: "test_filtering_ostream_flush.hpp"
Specifically, you should be able to see this in: boost_1_46_1\libs\iostreams\test\filtering_stream_flush_test.hpp
If you run these tests on your computer, do they pass? (You should be able to run bjam from the test directory). If so, how does this official test case differ from your own problem?
Also, there is another variation of a flush issue referenced in the ticket at: https://svn.boost.org/trac/boost/ticket/4728
Thanks, I will give it another look.
I have made a simple case demonstrating the issue :
#include
On 4/23/2011 1:16 PM, Bo Jensen wrote:
On Fri, Apr 22, 2011 at 10:55 PM, eg
wrote:
/* Typedef */ typedef boost::iostreams::code_converter
convert_to_narrow_sink; int main(int argc, char *argv[]) { std::ofstream strm("test.gz");
gzip_sink gzip(strm); convert_to_narrow_sink convert(gzip);
boost::iostreams::filtering_wostreambuf wbuf(convert,100);
std::wostream wout(&wbuf);
wout<<"Hello world!"<< std::endl; }
I hope someone can make it flush correctly or say I made a simple mistake..
In the interest of closure, can you confirm (from the comment you made in another thread), that this now works for you after changing the stream open call to be: std::ofstream strm("test.gz", std::ios_base::out | std::ios_base::binary); I know that it works for me when I tried it.
participants (2)
-
Bo Jensen
-
eg