readv_unix.go 542 B

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