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]

Doubts about in_avail vs showmanyc


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.

Let us consider again the current in_avail and showmanyc:

    streamsize
    in_avail()
    {
      streamsize __ret;
      if (_M_in_cur && _M_in_cur < _M_in_end)
        {
          if (_M_pback_init)
            {
              size_t __save_len =  _M_pback_end_save - _M_pback_cur_save;
              size_t __pback_len = _M_in_cur - _M_pback;
              __ret = __save_len - __pback_len;
            }
          else
            __ret = this->egptr() - this->gptr();
        }
      else
        __ret = this->showmanyc();
      return __ret;
    }

vs

template<typename _CharT, typename _Traits>
  streamsize
  basic_filebuf<_CharT, _Traits>::
  showmanyc()
  {
    streamsize __ret = -1;
    bool __testin = this->_M_mode & ios_base::in;

    if (__testin && this->is_open())
      __ret = this->_M_in_end - this->_M_in_cur;
    _M_last_overflowed = false;
    return __ret;
  }


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.

What I'm missing?

Thanks,
Paolo.


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