on plan 9 systems 0 writes are not discarded.

- erik

On Aug 10, 2015 7:11 AM, Giacomo Tesio <giacomo@tesio.it> wrote:
Hi, I've a probably naive question that I can't figure out.
I've just noticed that fcall(2) states
Read9pmsg calls read(2) multiple times, if necessary, to
read an entire 9P message into buf.  The return value is 0
for end of file, or -1 for error; it does not return partial
messages.

but I've noticed that a few client does not interpret a 0 return value as a EOF, eg

https://github.com/brho/plan9/blob/master/sys/src/cmd/usb/lib/fs.c#L604-L606
https://github.com/brho/plan9/blob/master/sys/src/cmd/usb/audio/audiofs.c#L889-L891
https://github.com/brho/plan9/blob/master/sys/src/cmd/aux/searchfs.c#L613-L615
https://github.com/brho/plan9/blob/master/sys/src/cmd/lnfs.c#L547-L551
https://github.com/brho/plan9/blob/master/sys/src/cmd/telco/telco.c#L935-L937

The comment there states that
/*
 * reading from a pipe or a network device
 * will give an error after a few eof reads.
 * however, we cannot tell the difference
 * between a zero-length read and an interrupt
 * on the processes writing to us,
 * so we wait for the error.
 */
However many other fs just handle errors and eof together, for example here:
https://github.com/brho/plan9/blob/master/sys/src/cmd/ip/ftpfs/ftpfs.c#L273-L279

I'm a bit confused about this. What's the proper use of the 0 return value?


Giacomo