Boost logo

Boost Users :

Subject: [Boost-users] Flushing a filtering_ostreambuf
From: jean-louis.a.leroy_at_[hidden]
Date: 2009-01-30 04:20:35


I have implemented a stream that sends output to the debugger (using OutputDebugString() in Windows):

class debug_output_sink : public boost::iostreams::sink {
public:
  debug_output_sink(int) { }
  std::streamsize write(const char* s, std::streamsize n);
  // also tried with:
  // struct category : boost::iostreams::sink::category, boost::iostreams::flushable_tag { };
  // bool flush() { return true; }
};

When I use it directly, flush() works fine:

    stream_buffer<debug_output_sink> debug_streambuf(debug_sink);
    ostream debug_stream(&debug_streambuf);
    debug_stream << "test\n";
    debug_stream.flush(); // characters appear immediately

However, when I put it in a filter, flushing the filter doesn't flush the stream:

  // scope
  {
    stream_buffer<debug_output_sink> debug_streambuf(debug_sink);
    ostream debug_stream(&debug_streambuf);
    
    filtering_ostreambuf filtering_buf;
    filtering_buf.push(debug_stream);
    
    ostream os(&filtering_buf);
    os << "test";
    os.flush(); // nothing
    filtering_buf.pubsync(); // nothing either
    filtering_buf.strict_sync(); // still nothing
  }
  // characters appear at last !

What I am missing here?

Thanks,
Jean-Louis Leroy





Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net