github.com/sagernet/sing@v0.2.6/common/rw/writev_posix.go (about)

     1  //go:build !windows
     2  
     3  package rw
     4  
     5  import (
     6  	"syscall"
     7  	"unsafe"
     8  )
     9  
    10  // Deprecated: use vectorised writer
    11  func WriteV(fd uintptr, data [][]byte) (int, error) {
    12  	iovecs := make([]syscall.Iovec, len(data))
    13  	for i := range iovecs {
    14  		iovecs[i].Base = &data[i][0]
    15  		iovecs[i].SetLen(len(data[i]))
    16  	}
    17  	var (
    18  		r uintptr
    19  		e syscall.Errno
    20  	)
    21  	for {
    22  		r, _, e = syscall.Syscall(syscall.SYS_WRITEV, fd, uintptr(unsafe.Pointer(&iovecs[0])), uintptr(len(iovecs)))
    23  		if e != syscall.EINTR {
    24  			break
    25  		}
    26  	}
    27  	if e != 0 {
    28  		return 0, e
    29  	}
    30  	return int(r), nil
    31  }