Boost C++ Libraries: Ticket #2998: Make file_sink flushable https://svn.boost.org/trac10/ticket/2998 <p> file_sink is hard to use as a debug log, since it does not flush. </p> <p> 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. </p> <p> This code: </p> <blockquote> <p> filtering_ostream fo; </p> </blockquote> <blockquote> <p> file_sink fsink("out.txt"); tee_filter&lt;file_sink&gt; tee_fsink(fsink); fo.push(tee_fsink); </p> </blockquote> <p> </p> <blockquote> <p> fo.push(cout); </p> </blockquote> <blockquote> <p> fo &lt;&lt; "some text"; fo.flush(); </p> </blockquote> <p> is very useful for arbitrary chains of debug logs, but not currently usable. </p> <p> The same issue applies to file, file_descriptor, and file_descriptor_sink. </p> <p> 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. </p> <p> I also tried to add flushable_file_descriptor, by privately inheriting from file_descriptor, and adding a flush call which calls ::<a class="missing wiki">FlushFileBuffers</a> on handle()... but so far that doesn't seem to work, so not attaching. </p> <p> Discussion at <a class="ext-link" href="http://groups.google.com/group/boost-list/browse_thread/thread/4c07e7c255e8143a/b9003b1b83c5a4db?lnk=raot&amp;pli=1"><span class="icon">​</span>http://groups.google.com/group/boost-list/browse_thread/thread/4c07e7c255e8143a/b9003b1b83c5a4db?lnk=raot&amp;pli=1</a> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2998 Trac 1.4.3 Andrew Schweitzer <a.schweitzer.grps@…> Thu, 07 May 2009 01:04:06 GMT attachment set https://svn.boost.org/trac10/ticket/2998 https://svn.boost.org/trac10/ticket/2998 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">flushable_file.hpp</span> </li> </ul> <p> sample implementation of flushable file_sink, copied from boost/iostreams/device/file_sink.hpp </p> Ticket Steven Watanabe Sun, 13 Jun 2010 18:18:58 GMT <link>https://svn.boost.org/trac10/ticket/2998#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2998#comment:1</guid> <description> <p> I don't think that file_descriptor_sink should be made flushable. It looks like <a class="missing wiki">FlushFileBuffers</a> is the Windows equivalent of fsync, and I rather doubt that standard streams use it. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Thu, 17 Jun 2010 15:19:34 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2998#comment:2 https://svn.boost.org/trac10/ticket/2998#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/63039" title="Make basic_file and basic_file_sync Flushable. Fixes #2998.">[63039]</a>) Make basic_file and basic_file_sync Flushable. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2998" title="#2998: Feature Requests: Make file_sink flushable (closed: fixed)">#2998</a>. </p> Ticket