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]

Re: Doubts about in_avail vs showmanyc


On Tue, Mar 04, 2003 at 09:34:16PM +0100, Paolo Carlini wrote:
> Hi Nathan, hi everyone
> 
> on second tought I have some doubts about your observations
> that showmanyc should return the _sum_ of of whatever is
> already in the buffer and what you get using recv/fstat.

I'm sorry to have made another mistake: ::fstat() tells the full
file size, so you would have to subtract the current position
from that, and ignore the count of characters still in the buffer
(unless it is more).  But that's not your point...

> Let us consider again the current in_avail and showmanyc:
> ...
> Two observations: first, in_avail calls showmanyc() only when it's
> sure that there are _no_ chars in the buffer; second, showmanyc()
> does almost nothing currently, since it's called exactly
> when it can only return zero (or -1).
> 
> Therefore, it seems that, in case there are actually chars in the
> buffer, it's in_avail which notice it _not_ showmanyc.

The descriptions of in_avail and showmanyc are different.  The 
former is supposed to tell you (quickly!) about what's buffered,
if any, where the latter is allowed to do more work and tell 
whatever it can learn.  It's protected, so it may be called by 
derived classes and exposed to users.  It is defined in terms of 
what behavior can be expected from underflow, which is likewise 
(only) protected and might be called with a non-empty buffer.  
underflow() must return characters already buffered before it 
starts returning newly-read characters or EOF.  So, the smallest
value showmanyc should return is egptr()-gptr(), but it might 
do better.

Users can call in_avail() in a loop, and it might be more efficient 
if they can read chunks bigger than BUFSIZ.

Nathan Myers
ncm-nospam at cantrip dot org


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