github.com/moqsien/xraycore@v1.8.5/common/buf/readv_unix.go (about) 1 //go:build illumos 2 // +build illumos 3 4 package buf 5 6 import "golang.org/x/sys/unix" 7 8 type unixReader struct { 9 iovs [][]byte 10 } 11 12 func (r *unixReader) Init(bs []*Buffer) { 13 iovs := r.iovs 14 if iovs == nil { 15 iovs = make([][]byte, 0, len(bs)) 16 } 17 for _, b := range bs { 18 iovs = append(iovs, b.v) 19 } 20 r.iovs = iovs 21 } 22 23 func (r *unixReader) Read(fd uintptr) int32 { 24 n, e := unix.Readv(int(fd), r.iovs) 25 if e != nil { 26 return -1 27 } 28 return int32(n) 29 } 30 31 func (r *unixReader) Clear() { 32 r.iovs = r.iovs[:0] 33 } 34 35 func newMultiReader() multiReader { 36 return &unixReader{} 37 }