@@ -25,6 +25,9 @@ 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 }
3033 if cap (iovecList ) > cap (w .iovecList ) {
@@ -36,17 +39,14 @@ func (w *SyscallVectorisedWriter) WriteVectorised(buffers []*buf.Buffer) error {
3639 for {
3740 var r0 uintptr
3841 //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 ())
42+ r0 , _ , innerErr = unix .RawSyscall (unix .SYS_WRITEV , fd , uintptr (unsafe .Pointer (unsafe .SliceData (writeIovecList ))), uintptr (len (writeIovecList )))
43+ writeN := uint64 (r0 )
44+ for writeN > 0 && len (writeIovecList ) > 0 {
45+ if writeIovecList [0 ].Len > writeN {
46+ writeIovecList [0 ].Base = (* byte )(unsafe .Add (unsafe .Pointer (writeIovecList [0 ].Base ), writeN ))
4547 break
4648 } else {
47- writeN -= buffers [0 ].Len ()
48- buffers [0 ].Release ()
49- buffers = buffers [1 :]
49+ writeN -= writeIovecList [0 ].Len
5050 writeIovecList = writeIovecList [1 :]
5151 }
5252 }
@@ -69,6 +69,9 @@ func (w *SyscallVectorisedPacketWriter) WriteVectorisedPacket(buffers []*buf.Buf
6969 defer buf .ReleaseMulti (buffers )
7070 iovecList := w .iovecList
7171 for _ , buffer := range buffers {
72+ if buffer .IsEmpty () {
73+ continue
74+ }
7275 iovecList = append (iovecList , buffer .Iovec (buffer .Len ()))
7376 }
7477 if cap (iovecList ) > cap (w .iovecList ) {
0 commit comments