Opened 9 years ago

Closed 7 years ago

#2998 closed Feature Requests (fixed)

Make file_sink flushable

Reported by: Andrew Schweitzer <a.schweitzer.grps@…> Owned by: Jonathan Turkanis
Milestone: Boost 1.39.0 Component: iostreams
Version: Boost 1.38.0 Severity: Not Applicable
Keywords: Cc:


file_sink is hard to use as a debug log, since it does not flush.

For example, when used when pushed into a filtering_ostream with cout, if flush is not called, characters don't appear on console or in file in a timely fashion. If flush is called, the characters on the console appear but not those in the file, because file_sink does not implement Flushable concept, and doesn't flush.

This code:

filtering_ostream fo;

file_sink fsink("out.txt"); tee_filter<file_sink> tee_fsink(fsink); fo.push(tee_fsink);


fo << "some text"; fo.flush();

is very useful for arbitrary chains of debug logs, but not currently usable.

The same issue applies to file, file_descriptor, and file_descriptor_sink.

If there is some reason these classes should not be modified to made flushable, then it seems easy to make flushable_* versions. Example of this attached, which was copied from file.hpp.

I also tried to add flushable_file_descriptor, by privately inheriting from file_descriptor, and adding a flush call which calls ::FlushFileBuffers? on handle()... but so far that doesn't seem to work, so not attaching.

Discussion at

Attachments (1)

flushable_file.hpp (5.6 KB) - added by Andrew Schweitzer <a.schweitzer.grps@…> 9 years ago.
sample implementation of flushable file_sink, copied from boost/iostreams/device/file_sink.hpp

Download all attachments as: .zip

Change History (3)

Changed 9 years ago by Andrew Schweitzer <a.schweitzer.grps@…>

Attachment: flushable_file.hpp added

sample implementation of flushable file_sink, copied from boost/iostreams/device/file_sink.hpp

comment:1 Changed 7 years ago by Steven Watanabe

I don't think that file_descriptor_sink should be made flushable. It looks like FlushFileBuffers? is the Windows equivalent of fsync, and I rather doubt that standard streams use it.

comment:2 Changed 7 years ago by Steven Watanabe

Resolution: fixed
Status: newclosed

(In [63039]) Make basic_file and basic_file_sync Flushable. Fixes #2998.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Jonathan Turkanis.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.