1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-02-14 12:15:22 -05:00

udp for shadowsocks

This commit is contained in:
v2ray
2016-01-28 21:30:05 +01:00
parent 1f9bd5f692
commit dde3f60e30
2 changed files with 97 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
package alloc
import (
"io"
"sync"
)
@@ -72,6 +73,19 @@ func (b *Buffer) Write(data []byte) (int, error) {
return len(data), nil
}
func (b *Buffer) Read(data []byte) (int, error) {
if b.Len() == 0 {
return 0, io.EOF
}
nBytes := copy(data, b.Value)
if nBytes == b.Len() {
b.Value = b.Value[:0]
} else {
b.Value = b.Value[nBytes:]
}
return nBytes, nil
}
type bufferPool struct {
chain chan []byte
allocator *sync.Pool