[ee122] Is stdin a stream?

Vern Paxson vern at icir.org
Tue Sep 18 14:32:27 PDT 2007


> I'm putting the input into a buffer using fgets (which will automatically
> tie everything up for me nicely)

Note, this works fine for the client, but will get you in trouble with
the server.  The reason is that the server needs to be able to multiplex
multiple inputs together with select().  If you use stdio for buffering,
then what can happen is that you read some of the characters out of stdio
(say a line's worth), but there are more characters still in the buffer.
In this case, when you call select() it will *not* necessarily indicate
that the associated file descriptor has activity, because as far as the
kernel is concerned, the data has already been consumed.

> also, what should the client do if a user types in a partial message and
> then hits the EOF key? should we assume the user wants to break the
> operation/connection or should we send out the data before the EOF key?

The spec says "The client program reads lines", so it's reasonable to
not consider those a line.

> finally, if an error does occur, should handling things gracefully mean
> trying to re-establish a connection, asking the user if they want to try and
> re-establish, returning 1 (error) or just returning 0 (success)?

It means generating a meaningful error message and exiting.

		Vern


More information about the ee122 mailing list