diff --git a/sys_exec.go b/sys_exec.go index 28171e36..8a7c5784 100644 --- a/sys_exec.go +++ b/sys_exec.go @@ -86,6 +86,7 @@ func readv(fd int, bs [][]byte, ivs []syscall.Iovec) (n int, err error) { } // syscall r, _, e := syscall.RawSyscall(syscall.SYS_READV, uintptr(fd), uintptr(unsafe.Pointer(&ivs[0])), uintptr(iovLen)) + resetIovecs(bs, ivs[:iovLen]) if e != 0 { return int(r), syscall.Errno(e) } diff --git a/sys_exec_test.go b/sys_exec_test.go index 54398df1..f35bb6e0 100644 --- a/sys_exec_test.go +++ b/sys_exec_test.go @@ -105,18 +105,23 @@ func TestReadv(t *testing.T) { w3, _ := syscall.Write(w, vs[2]) Equal(t, w1+w2+w3, 31) - var barrier = barrier{} - barrier.bs = [][]byte{ + var barrier = barrier{ + bs: make([][]byte, 4), + } + res := [][]byte{ make([]byte, 0), make([]byte, 10), make([]byte, 11), make([]byte, 10), } + for i := range res { + barrier.bs[i] = res[i] + } barrier.ivs = make([]syscall.Iovec, len(barrier.bs)) rn, err := readv(r, barrier.bs, barrier.ivs) MustNil(t, err) Equal(t, rn, 31) - for i, v := range barrier.bs { + for i, v := range res { t.Logf("READ [%d] %s", i, v) } }