Question - how do you determine if a C++ ifstream has buffered any
unread data? (without a blocking call like peek() or get())
I have some socket-based communication code where messages are sent
through C++ streams (ifstream/ofstream) bound to stream-type sockets.
The sockets are blocking, but I don't want the input-parsing code
to block on reads. So I am using the select() call on the ifstream's
file descriptor to determine whether there is any unread data on the
ifstream. But select() isn't accurate -- sometimes it claims that
there is no unread data when the ifstream still hasn't parsed all
the messages from the socket.
I think that this is a C++ stream buffering issue. It may be that
calls to ifstream.operator>>() (for parsing input) buffer all available
data from the socket into a private buffer. Then select() really sees
no unread data on the socket's file descriptor, even when my code
has not parsed all the socket messages from the ifstream.
So the question is - how do I tell when the ifstream has buffered
data available? (using non-blocking calls) Is there some member
function that tells you? What do gcount() and gtell() do?
Naval Research Lab, D.C.
Tel. (202) 767-3107