On Fri, Apr 22, 2011 at 10:55 PM, eg wrote:
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
#include
#include
#include
#include
#include
#include
#include
#include <cstdio>
#include <iostream>
#define WORKS
//#define DO_NOT WORK
/* Helper class for writing gzipped files */
class gzip_sink
{
public:
typedef char char_type;
typedef boost::iostreams::sink_tag category;
boost::iostreams::filtering_ostream sink_; /* Sink used
to push filters */
std::ofstream &outifstr_; /* Write
stream to be pushed into sink */
/* Constructor */
gzip_sink(std::ofstream &wrt) :
outifstr_(wrt)
{
#ifdef DO_NOT_WORK
/* Push gzip compressor */
sink_.push(boost::iostreams::gzip_compressor());
/* Push file writer */
sink_.push(outifstr_);
#endif
}
gzip_sink(const gzip_sink &rhs) :
outifstr_(rhs.outifstr_)
{
#ifdef DO_NOT_WORK
/* Push gzip compressor */
sink_.push(boost::iostreams::gzip_compressor());
/* Push file writer */
sink_.push(outifstr_);
#endif
}
/* Write function */
std::streamsize write( const char * s, std::streamsize n )
{
#ifdef WORKS
/* Push gzip compressor */
sink_.push(boost::iostreams::gzip_compressor());
/* Push file writer */
sink_.push(outifstr_);
#endif
/* Push write stream */
sink_.write(s,n);
#ifdef WORKS
sink_.pop();
sink_.pop();
#endif
return n;
}
};
/* 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..