Boost logo

Boost Users :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-06-11 09:23:52


Daryle,

Daryle Walker wrote:
 
> One compiler finished after the above 'fix'. The other (a variant of
> GCC 3.1) complained about missing symbols at link-time; it could not
> create the global objects hidden in Boost.CRC. (I haven't worked on
> the code in a long time; there could be quirks on compilers written
> after Boost.CRC.)
>
> When I ran the program under the compiler that worked, the "readsome"
> function always returned zero! There were no suitable substitutes; the
> "read" function doesn't tell you how many characters it read (bad if
> the last block isn't full) and the multi-character "get" functions use
> delimiters. So this program is stuck at single-character reads at the
> moment. Maybe I should switch to the stream-buffer method you used.
>
> Can you try this out to make sure the problems aren't just mine?

With gcc 3.3 on Linux, 'readsome' variant, 'get' variant and 'sbumpc'
variant all produce the same output. However, I'm not sure that 'readsome'
variant should work. Here's what "man std::iostream" tells about
'readsome'.

    if A > 0, extracts min(A,n)
    [ A = rdbuf()->in_avail() ]

    ...
    The goal is to empty the current buffer, and to not request any more
    from the external input sequence controlled by the streambuf.

Concerning 'in_avail()':

   If a read position is available, returns the number of characters
   available for reading before the buffer must be refilled. Otherwise
   returns the derived showmanyc().

Lastly, about 'showmanyc()':

   Base class version does nothing, returns zero.
  
So, this all leads to conclusion that 'readsome' is required to read all
characted currently available in stream buffer, but may ignore anything
else.

I believe that the right way is to use 'read' function, together with
'gcount()' with tells how many characters were read by the last unformatted
input operation. The main loop will become:

    do {
       ifs.read(buffer, BLOCK_SIZE);
       result.process_bytes(buffer, ifs.gcount());
    } while(ifs);

Of course, this variant produces the same results for me. Can you try with
your compiler?

- Volodya

P.S. In fact, I still don't understand what 'in_avail()' is good for...


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net