1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 01:27:03 -05:00

Remove dirty buffer logic

This commit is contained in:
V2Ray 2015-09-18 10:14:22 +02:00
parent d6e3040e48
commit 51bee920b2

View File

@ -8,31 +8,9 @@ const (
bufferSize = 32 * 1024
)
var (
dirtyBuffers = make(chan []byte, 1024)
)
func getBuffer() []byte {
var buffer []byte
select {
case buffer = <-dirtyBuffers:
default:
buffer = make([]byte, bufferSize)
}
return buffer
}
func putBuffer(buffer []byte) {
select {
case dirtyBuffers <- buffer:
default:
}
}
func ReaderToChan(stream chan<- []byte, reader io.Reader) error {
for {
buffer := make([]byte, bufferSize)
//buffer := getBuffer()
buffer := make([]byte, bufferSize)
nBytes, err := reader.Read(buffer)
if nBytes > 0 {
stream <- buffer[:nBytes]
@ -47,7 +25,6 @@ func ReaderToChan(stream chan<- []byte, reader io.Reader) error {
func ChanToWriter(writer io.Writer, stream <-chan []byte) error {
for buffer := range stream {
_, err := writer.Write(buffer)
//putBuffer(buffer)
if err != nil {
return err
}