github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/common/buf/readv_unix.go (about)

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