Skip to content

Commit 6189911

Browse files
committed
Fix SyscallVectorisedWriter
1 parent 6414292 commit 6189911

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

common/bufio/vectorised_unix.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

common/bufio/vectorised_windows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ func (w *SyscallVectorisedPacketWriter) WriteVectorisedPacket(buffers []*buf.Buf
4545
defer buf.ReleaseMulti(buffers)
4646
iovecList := w.iovecList
4747
for _, buffer := range buffers {
48+
if buffer.IsEmpty() {
49+
continue
50+
}
4851
iovecList = append(iovecList, buffer.Iovec(buffer.Len()))
4952
}
5053
var n uint32

0 commit comments

Comments
 (0)