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

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