difference between read and readsome

Other than their return value, are iostream::read and iostream::readsome the same? I read the descriptions of both and they seem to do the same thing.
[151 byte] By [stober] at [2007-11-19 12:18:11]
# 1 Re: difference between read and readsome
readsome can only read characters in the internal buffer of the streambuf, and does not read characters on the physical device.
For example, with readsome on cin, we are sure that it cannot request some input to the user.
It can be very useful to implement a fast version of getline.
Instead of reading each char, with streambuf::sgetc or istream::get(), we use readsome to read a little chunk of data, and then we search the data for a newline character, if there is no newline character, we effectively istream::read all these characters, then istream::get the next character (and it fills the buffer), and then reiterate the istream::readsome.
readsome returns the number of characters read. And this number of characters may be less than the number of requested characters, and may even be zero.
SuperKoko at 2007-11-9 0:47:47 >
# 2 Re: difference between read and readsome
According to Langer and Kreft in "Standard C++ IOStreams and Locales",

the difference is that "readsome does not wait for input (from a
terminal for instance), but returns immediately".

It seems like some time ago I tested this out under VC++ version 5
using cin.readsome(..) and it did not wait for input, but never seemed
to read anything when I put it in a loop. I never tested on other
compilers.
Philip Nicoletti at 2007-11-9 0:48:39 >
# 3 Re: difference between read and readsome
It seems like some time ago I tested this out under VC++ version 5
using cin.readsome(..) and it did not wait for input, but never seemed
to read anything when I put it in a loop. I never tested on other
compilers.
It is important to note a few things:

readsome may always returns zero and read nothing : it is a legal compiler behavior. And i think that it is the VC++ behavior.
From the previous point, you understand that readsome may only be used to potentially optimize a piece of code, if the compiler is smart enough to not always return zero (for example Borland C++).
The trivial implementation of readsome is a call to read with the min((value returned by streambuf::in_avail), (value specified as parameter of readsome))
in_avail may always return 0, and it is probably what VC++ does.
Under Borland C++ 5.0, the implementation (it is the natural implementation) of in_avail returns streambuf::egptr()-streambuf::gptr().
With that implementation, it is easy to 'flush the cin input', that is ignore all characters in the internal cin buffer.
SuperKoko at 2007-11-9 0:49:43 >
# 4 Re: difference between read and readsome
thanks for your replies. I am attempting to port a form of fstream to eVC++ 3.0 compiler, which does not natively support it. It will be a thin wrapper for FILE and associated functions. There are a few functions that cannot be ported, such as FILE's setbuf() does not exist, so I will not be able to implement readsome() . WinCE does not have a console, so none of iostream can be implemented or any other class that depends on it. My fstream is going to be very simple -- not using templates (I hate most of them because they are difficult to understand), just plain c++ class.
stober at 2007-11-9 0:50:51 >
# 5 Re: difference between read and readsome
You don't need to rely on the FILE buffering.
You should derive filebuf from streambuf, and then write fstream derived from iostream, and using filebuf.
SuperKoko at 2007-11-9 0:51:45 >
# 6 Re: difference between read and readsome
streambuf is not available either. I would have to write that from scratch too.
stober at 2007-11-9 0:52:44 >