@@ -27,35 +27,36 @@ func (w *SyscallVectorisedWriter) WriteVectorised(buffers []*buf.Buffer) error {
2727 for _ , buffer := range buffers {
2828 iovecList = append (iovecList , buffer .Iovec (buffer .Len ()))
2929 }
30+ if cap (iovecList ) > cap (w .iovecList ) {
31+ w .iovecList = iovecList [:0 ]
32+ }
3033 var innerErr unix.Errno
3134 err := w .rawConn .Write (func (fd uintptr ) (done bool ) {
35+ writeIovecList := iovecList
3236 for {
3337 var r0 uintptr
3438 //nolint:staticcheck
35- r0 , _ , innerErr = unix .RawSyscall (unix .SYS_WRITEV , fd , uintptr (unsafe .Pointer (& iovecList [0 ])), uintptr (len (iovecList )))
39+ r0 , _ , innerErr = unix .RawSyscall (unix .SYS_WRITEV , fd , uintptr (unsafe .Pointer (& writeIovecList [0 ])), uintptr (len (writeIovecList )))
3640 writeN := int (r0 )
3741 for writeN > 0 {
3842 if buffers [0 ].Len () > writeN {
3943 buffers [0 ].Advance (writeN )
40- iovecList [0 ] = buffers [0 ].Iovec (buffers [0 ].Len ())
44+ writeIovecList [0 ] = buffers [0 ].Iovec (buffers [0 ].Len ())
4145 break
4246 } else {
4347 writeN -= buffers [0 ].Len ()
4448 buffers [0 ].Release ()
4549 buffers = buffers [1 :]
46- iovecList = iovecList [1 :]
50+ writeIovecList = writeIovecList [1 :]
4751 }
4852 }
49- if innerErr == unix .EINTR || (innerErr == 0 && len (iovecList ) > 0 ) {
53+ if innerErr == unix .EINTR || (innerErr == 0 && len (writeIovecList ) > 0 ) {
5054 continue
5155 }
5256 return innerErr != unix .EAGAIN
5357 }
5458 })
5559 common .ClearArray (iovecList )
56- if cap (iovecList ) > cap (w .iovecList ) {
57- w .iovecList = iovecList [:0 ]
58- }
5960 if innerErr != 0 {
6061 err = os .NewSyscallError ("SYS_WRITEV" , innerErr )
6162 }
@@ -70,7 +71,10 @@ func (w *SyscallVectorisedPacketWriter) WriteVectorisedPacket(buffers []*buf.Buf
7071 for _ , buffer := range buffers {
7172 iovecList = append (iovecList , buffer .Iovec (buffer .Len ()))
7273 }
73- var innerErr error
74+ if cap (iovecList ) > cap (w .iovecList ) {
75+ w .iovecList = iovecList [:0 ]
76+ }
77+ var innerErr unix.Errno
7478 err := w .rawConn .Write (func (fd uintptr ) (done bool ) {
7579 var msg unix.Msghdr
7680 name , nameLen := ToSockaddr (destination .AddrPort ())
@@ -89,11 +93,8 @@ func (w *SyscallVectorisedPacketWriter) WriteVectorisedPacket(buffers []*buf.Buf
8993 }
9094 })
9195 common .ClearArray (iovecList )
92- if cap (iovecList ) > cap (w .iovecList ) {
93- w .iovecList = iovecList [:0 ]
94- }
95- if innerErr != nil {
96- err = innerErr
96+ if innerErr != 0 {
97+ err = os .NewSyscallError ("SYS_SENDMSG" , innerErr )
9798 }
9899 return err
99100}
0 commit comments