[Mono-list] StreamReader.Peek() and support for character devices
Tony Garnock-Jones
tonyg@lshift.net
Tue, 27 May 2003 23:30:07 +0100
Hi all.
I noticed this oddity during interactive reading from the console:
1. calling System.Console.In.Peek() at the start of a program
blocks, waiting for the first character to be entered,
and when one comes available, returns it (no surprises)
2. Peek() works as you'd expect until just after the newline
of the first line entered - at which point it returns -1
even though I haven't typed the EOF character at it yet
3. This doesn't fit my expectation of what would happen (which
is that Peek() would again block, waiting for the next line
of input - unless the stream was ended with ^D on unix or
^Z on windows, in which case -1 for an EOF signal is appropriate)
This happens both with Mono on Linux and MS.NET on Windows. If this is
the correct, intended behaviour, then it seems inconsistent:
a) it should immediately return -1 at program start, since no input
is immediately available at that point either, OR
b) Read() should return -1 at the end of the first line to be
consistent with Peek(). It doesn't - it blocks.
What's correct? Can someone with a more detailed overview of the
specified behaviour of StreamReader etc. please check?
Tony