diff --git a/transport/internet/kcp/output.go b/transport/internet/kcp/output.go index 98b054f1..36614b9d 100644 --- a/transport/internet/kcp/output.go +++ b/transport/internet/kcp/output.go @@ -28,8 +28,7 @@ func (v *SimpleSegmentWriter) Write(seg Segment) error { v.Lock() defer v.Unlock() - v.buffer.AppendSupplier(seg.Bytes()) + v.buffer.Reset(seg.Bytes()) _, err := v.writer.Write(v.buffer.Bytes()) - v.buffer.Clear() return err } diff --git a/transport/internet/kcp/segment.go b/transport/internet/kcp/segment.go index 7e8930cb..6fba4d2b 100644 --- a/transport/internet/kcp/segment.go +++ b/transport/internet/kcp/segment.go @@ -61,12 +61,13 @@ func (v *DataSegment) Command() Command { return CommandData } -func (v *DataSegment) SetData(b []byte) { +func (v *DataSegment) SetData(data []byte) { if v.Data == nil { v.Data = buf.NewSmall() } - v.Data.Clear() - v.Data.Append(b) + v.Data.Reset(func(b []byte) (int, error) { + return copy(b, data), nil + }) } func (v *DataSegment) Bytes() buf.Supplier {