Permalink
Browse files

Signal EOF correctly

The plan9 manual does not explicitly state how a server should tell
a client that it has reached end-of-file. From observing many existing
clients, I have determined that a client decides that end-of-file is
reached when

- A read returns less data than what was asked for (`9pfuse`)
- A read returns 0 bytes (`9p`, `ixpc`, v9fs)

These two conditions are compatible, and are implemented with this
commit.
  • Loading branch information...
droyo committed Aug 20, 2016
1 parent 9ace41f commit 2b3641b405a4074cabe891e830bae2f7e31461af
Showing with 7 additions and 4 deletions.
  1. +5 −3 session.go
  2. +2 −1 styxproto/encoder.go
@@ -225,11 +225,13 @@ func (s *Session) handleTread(cx context.Context, msg styxproto.Tread, file file
buf := make([]byte, int(msg.Count()))

// TODO(droyo) cancellation
_, err := file.rwc.ReadAt(buf, msg.Offset())
if err != nil {
n, err := file.rwc.ReadAt(buf, msg.Offset())

if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF {
s.conn.Rerror(msg.Tag(), "%v", err)
} else {
s.conn.Rread(msg.Tag(), buf[:n])
}
s.conn.Rread(msg.Tag(), buf)
return true
}

@@ -298,7 +298,8 @@ func (enc *Encoder) Rread(tag uint16, data []byte) (n int, err error) {
msize = MinBufSize
}
msize -= int64(minSizeLUT[msgRread])
for len(data) > 0 {
for first := true ; first || len(data) > 0; {
first = false
chunk := data
if int64(len(data)) > msize {
chunk = data[:msize]

0 comments on commit 2b3641b

Please sign in to comment.