浏览代码

Leverage buffer.Read

v2ray 9 年之前
父节点
当前提交
089de290ad
共有 1 个文件被更改,包括 3 次插入5 次删除
  1. 3 5
      common/io/chan_reader.go

+ 3 - 5
common/io/chan_reader.go

@@ -45,14 +45,12 @@ func (this *ChanReader) Read(b []byte) (int, error) {
 			return 0, io.EOF
 		}
 	}
-	nBytes := copy(b, this.current.Value)
-	if nBytes == this.current.Len() {
+	nBytes, err := this.current.Read(b)
+	if this.current.IsEmpty() {
 		this.current.Release()
 		this.current = nil
-	} else {
-		this.current.SliceFrom(nBytes)
 	}
-	return nBytes, nil
+	return nBytes, err
 }
 
 func (this *ChanReader) Release() {