This is the mail archive of the
mailing list for the libstdc++ project.
Re: Toward a satisfactory showmanyc
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: Nathan Myers <ncm-nospam at cantrip dot org>
- Cc: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>
- Date: Fri, 21 Mar 2003 00:37:08 +0100
- Subject: Re: Toward a satisfactory showmanyc
- References: <3E7A1BFE.firstname.lastname@example.org> <20030320232123.GM15175@tofu.dreamhost.com>
Nathan Myers wrote:
Certainly the overwhelming bulk of the implementation work will be in
the autoconf machinery. (Fortunately, "#ifdef FIONREAD" works, which
might reduce complexity a little bit.) Ok, thanks. In the next days I will start implementing your detailed
I am sensitive about the performance implications of calling fstat()
first. On any given platform ioctl() or FIONREAD might not exist.
I'm thinking it should try, in order:
If the test is #ifdef'ed out, fine. If it fails, fine.
If it reports a positive number, return it. If it reports
a negative number, it's probably a file bigger than 2G, so
skip to the next test. Otherwise...
A cheap test -- if it reports "not ready", return 0.
Note that it reports "ready" if the next read will say EOF,
so "ready" just tells us it's worth looking more closely.
If it says the fd is a file, then use st_size as in your
existing patch. If it says the fd is a pipe or stream, the
ioctl above must have been #ifdef'd out; but, if it reports
a non-zero st_size (which works on some targets), use it.
If it fails, report 0. Probably we should be using fstat64
where it exists.
when I posted my first message, today, I didn't know how to check for a
ioctl, but in the meanwhile I learned that (from libjava ;) and
rather easily doable exactly as you write.
For the case of a socket, we could use a funny search after all the
above has failed: set the SO_RCVLOWAT socket option to increasing
values until poll() reports "not ready", and then restore
SO_RECVLOWAT and report the last "ready" value. The problem is
that since it reports "ready" at EOF, you can't trust it if it
never reports "not ready". So, if you get tired of quadrupling
(e.g. you've hit 64K, seven calls) and still get "ready", try
a really large value, e.g. 1<<24, -- and if it still reports ready
you know it's at EOF, and you report -1; otherwise, just report the
64K.;) Well, in this first round I would probably leave out this refinement
for sockets and
Note that setsockopt SO_RCVLOWAT (like ioctl) is not required by POSIX.
Of course it's up to you to decide how much work you want to put into
supporting this; at whatever point you think you and library have
tried hard enough, return 0.
also the large file support part: we still hope to have this in before
3.3, and we have not
much time to write and test thoroughly the whole beast.