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) { ...@@ -243,33 +243,35 @@ func CopyFileInfo(fi *os.FileInfo, attr *Attr) {
func writev(fd int, iovecs *syscall.Iovec, cnt int) (n int, errno int) { 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)) n1, _, e1 := syscall.Syscall(
n = int(n1) syscall.SYS_WRITEV,
errno = int(e1) uintptr(fd), uintptr(unsafe.Pointer(iovecs)), uintptr(cnt))
return return int(n1), int(e1)
} }
func Writev(fd int, packet [][]byte) (n int, err os.Error) { func Writev(fd int, packet [][]byte) (n int, err os.Error) {
if len(packet) == 0 { iovecs := make([]syscall.Iovec, 0, len(packet))
return
}
iovecs := make([]syscall.Iovec, len(packet))
j := 0 for _, v := range packet {
for i, v := range packet {
if v == nil || len(v) == 0 { if v == nil || len(v) == 0 {
continue continue
} }
iovecs[j].Base = (*byte)(unsafe.Pointer(&packet[i][0])) vec := syscall.Iovec{
iovecs[j].SetLen(len(packet[i])) Base: &v[0],
j++ }
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 { if errno != 0 {
err = os.NewSyscallError("writev", errno) err = os.NewSyscallError("writev", errno)
} }
return return n, err
} }
func CountCpus() int { 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