This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Long dead thread: Re: The patch for PR libstdc++/14097.


On Wed, Feb 11, 2004 at 08:01:38PM -0600, Benjamin Kosnik wrote:
> 
> >Then, for reasons of symmetry, we should expose the FILE* when we wrap the
> >other layer.  Like this:
> 
> I don't have a problem adding this kind of thing to the extension
> filebufs. Either, both. Submit a patch, ChangeLog entry, the whole deal.
>
> I do have a problem with adding fd/FILE accessors to std::basic_filebuf,
> but this isn't what you are asking (at this point in the thread.)

I know this is a long stale thread, but from what I remember of the
"long, torrid history" :) was that "if you wanted to do something
weird, write your own filebuf".  Well, as a reference for the next time
this comes up, perhaps, I did just that long ago.

I have a logging system based on iostreams, and I do two special
things.  First, I have "class fdfilebuf : public std::filebuf" which
hacks in an "int fd()" that I need for some fork() and other
purposes.  This is clearly an unsupported extension since it's in user
code :)

Second, I have "class logfilebuf : public fdfilebuf" that overrides
overflow() and sync() to call syslog() (and then chains to the base
class to write to the file, too).  I consider this to be an extreme
customization, and it only takes a couple of dozen or so lines of user
code. 

I agree with what you were saying on this, and I think it users can
get to the details they need with the appropriate caveats without
hackery inside libstdc++.  In fact, from my (incomplete) reading of
Langer and Kreft's "Standard C++ IOStreams and Locales", this is the
intended approach for extending IOStreams functionality.  There's a
whole section (3.3) of the text that discusses the general topic.

For reference, I've attached a simplified concept implementation of
how you can do this sort of thing in real applications.  The sample
makes some compromises, but it admits as much.  This works with
gcc-3.4.0, and a form of it has worked since the gcc-2.95.x days.

It is important to note that I've combined two solutions into this
single sample.  The syslog() functionality does not depend on being
able to get the UNIX file descriptor or vice versa.

-- 
------------------------------------------------------------------
Brad Spencer - spencer@infointeractive.com - "It's quite nice..."
Systems Architect | InfoInterActive Corp. | A Canadian AOL Company

Attachment: sample.cc
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]