1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -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 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 { func ReaderToChan(stream chan<- []byte, reader io.Reader) error {
for { for {
buffer := make([]byte, bufferSize) buffer := make([]byte, bufferSize)
//buffer := getBuffer()
nBytes, err := reader.Read(buffer) nBytes, err := reader.Read(buffer)
if nBytes > 0 { if nBytes > 0 {
stream <- buffer[:nBytes] 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 { func ChanToWriter(writer io.Writer, stream <-chan []byte) error {
for buffer := range stream { for buffer := range stream {
_, err := writer.Write(buffer) _, err := writer.Write(buffer)
//putBuffer(buffer)
if err != nil { if err != nil {
return err return err
} }