
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<gzip_sink> to be able to use gzip with wide streams.