Topic: Implementing iostream on serial ports or IP sockets : eofbit
Author: drh@bcisa.com ("\"BCI sa\"")
Date: Thu, 14 Nov 2002 17:30:27 +0000 (UTC) Raw View
As far as I know, to deal with stream IO errors the C++ standard offers the
following state flags:
badbit (critical error in stream buffer)
eofbit (End-Of-File reached while extracting)
failbit (failure extracting from stream)
I am currently implementing specific iostreams to work on serial ports, IP
sockets ... and I wish to comply as most as possible with the C++ standard.
Thus I am wondering if the C++ standard specifies something about the
setting of the "eofbit" :
(1)
Is there a case when the "eofbit" should be set when the stream is *not* a
file ?
(2)
When dealing with files, when you try to read more than remains in the file,
the "eofbit" is of course set, but is the "failbit" also set ?
Regards,
Cyril.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: news@evo6.com (Andy Sawyer)
Date: Fri, 15 Nov 2002 01:57:25 +0000 (UTC) Raw View
In article <aqvv7t$3qt$1@s1.read.news.oleane.net>,
on Thu, 14 Nov 2002 17:30:27 +0000 (UTC),
drh@bcisa.com ("\"BCI sa\"") wrote:
> As far as I know, to deal with stream IO errors the C++ standard offers the
> following state flags:
>
> badbit (critical error in stream buffer)
> eofbit (End-Of-File reached while extracting)
> failbit (failure extracting from stream)
Table 85 (27.4.2.1.3) describes these bits as:
Element Effect if set
badbit indicates a loss of integrity in an input or output sequence
(such as an irrecoverable read error from a file);
eofbit indicates that an input operation reached the end of an
input sequence;
failbit indicates that an input operation failed to read the
expected characters, or that an output operation failed
to generate the desired characters.
> Thus I am wondering if the C++ standard specifies something about the
> setting of the "eofbit" :
>
> (1)
> Is there a case when the "eofbit" should be set when the stream is *not* a
> file ?
Certainly. It might be better termed "eoibit", since it is used to
indicate the end of an input sequence.
> (2)
> When dealing with files, when you try to read more than remains in
> the file, the "eofbit" is of course set, but is the "failbit"
> also set ?
Yes. (27.6.1.2 and 27.6.1.3 are pretty clear on this)
However, if I understand what you're doing correctly, you probably
ought to look at implementing stream buffers rather than iostreams,
the use your vendor's existing iostream implementation to access the
stream buffers.
Regards,
Andy S.
--
"Light thinks it travels faster than anything but it is wrong. No matter
how fast light travels it finds the darkness has always got there first,
and is waiting for it." -- Terry Pratchett, Reaper Man
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]