You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/transport/internet/kcp/output.go

35 lines
525 B

package kcp
import (
"io"
"sync"
"v2ray.com/core/common/buf"
)
type SegmentWriter interface {
Write(seg Segment) error
}
type SimpleSegmentWriter struct {
sync.Mutex
buffer *buf.Buffer
writer io.Writer
}
func NewSegmentWriter(writer io.Writer) SegmentWriter {
return &SimpleSegmentWriter{
writer: writer,
buffer: buf.NewSmall(),
}
}
func (v *SimpleSegmentWriter) Write(seg Segment) error {
v.Lock()
defer v.Unlock()
v.buffer.Reset(seg.Bytes())
_, err := v.writer.Write(v.buffer.Bytes())
return err
}