1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-27 04:25:44 -05:00

Use Buffer as a writer

This commit is contained in:
V2Ray
2015-10-10 20:52:13 +02:00
parent 32ab3dcd61
commit a77f62428a
2 changed files with 13 additions and 4 deletions

View File

@@ -50,6 +50,11 @@ func (b *Buffer) IsFull() bool {
return len(b.Value) == cap(b.Value)
}
func (b *Buffer) Write(data []byte) (int, error) {
b.Append(data)
return len(data), nil
}
type bufferPool struct {
chain chan []byte
bufferSize int
@@ -98,7 +103,10 @@ func (p *bufferPool) cleanup(tick <-chan time.Time) {
continue
}
for delta := p.buffers2Keep - pSize; delta > 0; delta-- {
p.chain <- make([]byte, p.bufferSize)
select {
case p.chain <- make([]byte, p.bufferSize):
default:
}
}
}
}