Commit de161fea authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Cleanup code for writev.

parent 9d593fde
......@@ -243,33 +243,35 @@ func CopyFileInfo(fi *os.FileInfo, attr *Attr) {
func writev(fd int, iovecs *syscall.Iovec, cnt int) (n int, errno int) {
n1, _, e1 := syscall.Syscall(syscall.SYS_WRITEV, uintptr(fd), uintptr(unsafe.Pointer(iovecs)), uintptr(cnt))
n = int(n1)
errno = int(e1)
return
n1, _, e1 := syscall.Syscall(
syscall.SYS_WRITEV,
uintptr(fd), uintptr(unsafe.Pointer(iovecs)), uintptr(cnt))
return int(n1), int(e1)
}
func Writev(fd int, packet [][]byte) (n int, err os.Error) {
if len(packet) == 0 {
return
}
iovecs := make([]syscall.Iovec, len(packet))
iovecs := make([]syscall.Iovec, 0, len(packet))
j := 0
for i, v := range packet {
for _, v := range packet {
if v == nil || len(v) == 0 {
continue
}
iovecs[j].Base = (*byte)(unsafe.Pointer(&packet[i][0]))
iovecs[j].SetLen(len(packet[i]))
j++
vec := syscall.Iovec{
Base: &v[0],
}
vec.SetLen(len(v))
iovecs = append(iovecs, vec)
}
if len(iovecs) == 0 {
return 0, nil
}
n, errno := writev(fd, (*syscall.Iovec)(unsafe.Pointer(&iovecs[0])), j)
n, errno := writev(fd, &iovecs[0], len(iovecs))
if errno != 0 {
err = os.NewSyscallError("writev", errno)
}
return
return n, err
}
func CountCpus() int {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment