Commit f47438ec authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Comment read.go.

parent ebb11341
...@@ -5,8 +5,18 @@ import ( ...@@ -5,8 +5,18 @@ import (
"syscall" "syscall"
) )
// The result of Read is an array of bytes, but for performance
// reasons, we can also return data as a file-descriptor/offset/size
// tuple. If the backing store for the file system is another
// filesystem, this reduces the amount of copying and memory in use.
//
// If at any point, the raw data is needed, ReadResult.Read() will
// load the raw data.
type ReadResult struct { type ReadResult struct {
// Errno code for the read.
Status Status
// Raw bytes for the read.
Data []byte Data []byte
// If Data is nil and Status OK, splice from the following // If Data is nil and Status OK, splice from the following
...@@ -15,6 +25,9 @@ type ReadResult struct { ...@@ -15,6 +25,9 @@ type ReadResult struct {
// Offset within Fd, or -1 to use current offset. // Offset within Fd, or -1 to use current offset.
FdOff int64 FdOff int64
// Size of data to be loaded. Actual data available may be
// less at the EOF.
FdSize int FdSize int
} }
...@@ -29,6 +42,8 @@ func (r *ReadResult) Size() int { ...@@ -29,6 +42,8 @@ func (r *ReadResult) Size() int {
return r.FdSize return r.FdSize
} }
// Reads raw bytes from file descriptor if necessary, using the passed
// buffer as storage.
func (r *ReadResult) Read(buf []byte) Status { func (r *ReadResult) Read(buf []byte) Status {
if r.Data != nil || !r.Ok() { if r.Data != nil || !r.Ok() {
return r.Status return r.Status
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment