Boost logo

Boost Users :

Subject: [Boost-users] [iostreams] How do you flush an entire filter chain?
From: Adam Nielsen (a.nielsen_at_[hidden])
Date: 2010-12-04 19:46:22


Hi all,

I have some code that uses standard C++ iostreams and I would like to use
Boost iostreams to insert a filter in the process to provide transparent XOR
encryption/decryption without needing to modify the existing code.

I have written a filter that applies the algorithm, and I create a
filtering_stream<io::seekable> "stack" which has the XOR filter pushed onto
it, followed by the original iostream. I then pass this stack along to the
original function and for the most part it works.

However when the original code tries to flush() the changes back to disk, the
filter only calls flush() on the first item in the stack. This means the XOR
algorithm has its flush() function called, but the iostream (next in line on
the stack) does not.

If I remove the XOR algorithm (leaving the filter stack in place) then it does
call flush() on the original iostream now that it is the first element in the
stack.

So I would like to know if there is a way to flush an entire filter stack,
rather than just the top-most element in the stack.

My XOR filter function doesn't actually perform any caching so its flush()
function simply returns true, as this seems to be required from what I could
make out in the docs about flushing. I was unable to find any mention in the
docs of how flush() should behave in a filter (not even a function signature)
so I am not sure if this is correct! I just copied it off some of the test
code as that was the only place I could find anything about it.

Many thanks,
Adam.


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