mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Internal change.
PiperOrigin-RevId: 390318725
This commit is contained in:
@@ -207,58 +207,6 @@ func (r FromIOReader) readToBlock(dst Block, buf []byte) (int, []byte, error) {
|
||||
return wbn, buf, rerr
|
||||
}
|
||||
|
||||
// FromIOReaderAt implements Reader for an io.ReaderAt. Does not repeatedly
|
||||
// invoke io.ReaderAt.ReadAt because ReadAt is more strict than Read. A partial
|
||||
// read indicates an error. This is not thread-safe.
|
||||
type FromIOReaderAt struct {
|
||||
ReaderAt io.ReaderAt
|
||||
Offset int64
|
||||
}
|
||||
|
||||
// ReadToBlocks implements Reader.ReadToBlocks.
|
||||
func (r FromIOReaderAt) ReadToBlocks(dsts BlockSeq) (uint64, error) {
|
||||
var buf []byte
|
||||
var done uint64
|
||||
for !dsts.IsEmpty() {
|
||||
dst := dsts.Head()
|
||||
var n int
|
||||
var err error
|
||||
n, buf, err = r.readToBlock(dst, buf)
|
||||
done += uint64(n)
|
||||
if n != dst.Len() {
|
||||
return done, err
|
||||
}
|
||||
dsts = dsts.Tail()
|
||||
if err != nil {
|
||||
if dsts.IsEmpty() && err == io.EOF {
|
||||
return done, nil
|
||||
}
|
||||
return done, err
|
||||
}
|
||||
}
|
||||
return done, nil
|
||||
}
|
||||
|
||||
func (r FromIOReaderAt) readToBlock(dst Block, buf []byte) (int, []byte, error) {
|
||||
// io.Reader isn't safecopy-aware, so we have to buffer Blocks that require
|
||||
// safecopy.
|
||||
if !dst.NeedSafecopy() {
|
||||
n, err := r.ReaderAt.ReadAt(dst.ToSlice(), r.Offset)
|
||||
r.Offset += int64(n)
|
||||
return n, buf, err
|
||||
}
|
||||
if len(buf) < dst.Len() {
|
||||
buf = make([]byte, dst.Len())
|
||||
}
|
||||
rn, rerr := r.ReaderAt.ReadAt(buf[:dst.Len()], r.Offset)
|
||||
r.Offset += int64(rn)
|
||||
wbn, wberr := Copy(dst, BlockFromSafeSlice(buf[:rn]))
|
||||
if wberr != nil {
|
||||
return wbn, buf, wberr
|
||||
}
|
||||
return wbn, buf, rerr
|
||||
}
|
||||
|
||||
// FromIOWriter implements Writer for an io.Writer by repeatedly invoking
|
||||
// io.Writer.Write until it returns an error or partial write.
|
||||
//
|
||||
|
||||
@@ -362,7 +362,12 @@ func main() {
|
||||
fmt.Fprintf(outputFile, " stateSourceObject.LoadWait(%d, &%s.%s)\n", fields[name], recv, name)
|
||||
}
|
||||
emitSaveValue := func(name, typName string) {
|
||||
fmt.Fprintf(outputFile, " var %sValue %s = %s.save%s()\n", name, typName, recv, camelCased(name))
|
||||
// Emit typName to be more robust against code generation bugs,
|
||||
// but instead of one line make two lines to silence ST1023
|
||||
// finding (i.e. avoid nogo finding: "should omit type $typName
|
||||
// from declaration; it will be inferred from the right-hand side")
|
||||
fmt.Fprintf(outputFile, " var %sValue %s\n", name, typName)
|
||||
fmt.Fprintf(outputFile, " %sValue = %s.save%s()\n", name, recv, camelCased(name))
|
||||
fmt.Fprintf(outputFile, " stateSinkObject.SaveValue(%d, %sValue)\n", fields[name], name)
|
||||
}
|
||||
emitSave := func(name string) {
|
||||
|
||||
Reference in New Issue
Block a user