From 9562ad17d70080171efc81185b91c636b36b9de1 Mon Sep 17 00:00:00 2001 From: zhandaohong Date: Thu, 7 Dec 2023 14:36:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dsys=5Fexec=5Ftest.go?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E4=B8=ADTestReadv=E6=B5=8B=E8=AF=95=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E4=BD=BF=E7=94=A8=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sys_exec.go | 1 + sys_exec_test.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) 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) } }