@@ -25,9 +25,14 @@ func (w *SyscallVectorisedWriter) WriteVectorised(buffers []*buf.Buffer) error {
2525 defer buf .ReleaseMulti (buffers )
2626 iovecList := w .iovecList
2727 for _ , buffer := range buffers {
28+ if buffer .IsEmpty () {
29+ continue
30+ }
2831 iovecList = append (iovecList , buffer .Iovec (buffer .Len ()))
2932 }
30- if cap (iovecList ) > cap (w .iovecList ) {
33+ if len (iovecList ) == 0 {
34+ return nil
35+ } else if cap (iovecList ) > cap (w .iovecList ) {
3136 w .iovecList = iovecList [:0 ]
3237 }
3338 var innerErr unix.Errno
@@ -36,17 +41,14 @@ func (w *SyscallVectorisedWriter) WriteVectorised(buffers []*buf.Buffer) error {
3641 for {
3742 var r0 uintptr
3843 //nolint:staticcheck
39- r0 , _ , innerErr = unix .RawSyscall (unix .SYS_WRITEV , fd , uintptr (unsafe .Pointer (& writeIovecList [0 ])), uintptr (len (writeIovecList )))
40- writeN := int (r0 )
41- for writeN > 0 {
42- if buffers [0 ].Len () > writeN {
43- buffers [0 ].Advance (writeN )
44- writeIovecList [0 ] = buffers [0 ].Iovec (buffers [0 ].Len ())
44+ r0 , _ , innerErr = unix .RawSyscall (unix .SYS_WRITEV , fd , uintptr (unsafe .Pointer (unsafe .SliceData (writeIovecList ))), uintptr (len (writeIovecList )))
45+ writeN := uint64 (r0 )
46+ for writeN > 0 && len (writeIovecList ) > 0 {
47+ if writeIovecList [0 ].Len > writeN {
48+ writeIovecList [0 ].Base = (* byte )(unsafe .Add (unsafe .Pointer (writeIovecList [0 ].Base ), writeN ))
4549 break
4650 } else {
47- writeN -= buffers [0 ].Len ()
48- buffers [0 ].Release ()
49- buffers = buffers [1 :]
51+ writeN -= writeIovecList [0 ].Len
5052 writeIovecList = writeIovecList [1 :]
5153 }
5254 }
@@ -69,6 +71,9 @@ func (w *SyscallVectorisedPacketWriter) WriteVectorisedPacket(buffers []*buf.Buf
6971 defer buf .ReleaseMulti (buffers )
7072 iovecList := w .iovecList
7173 for _ , buffer := range buffers {
74+ if buffer .IsEmpty () {
75+ continue
76+ }
7277 iovecList = append (iovecList , buffer .Iovec (buffer .Len ()))
7378 }
7479 if cap (iovecList ) > cap (w .iovecList ) {
0 commit comments