mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 23:47:07 -05:00
reduce memory consumption on readOne
This commit is contained in:
parent
c5a384195a
commit
844f6937a4
@ -8,7 +8,17 @@ import (
|
||||
)
|
||||
|
||||
func readOne(r io.Reader) (*Buffer, error) {
|
||||
// Use an one-byte buffer to wait for incoming payload.
|
||||
var firstByte [1]byte
|
||||
nBytes, err := r.Read(firstByte[:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
b := New()
|
||||
if nBytes > 0 {
|
||||
copy(b.Extend(int32(nBytes)), firstByte[:])
|
||||
}
|
||||
for i := 0; i < 64; i++ {
|
||||
_, err := b.ReadFrom(r)
|
||||
if !b.IsEmpty() {
|
||||
@ -20,6 +30,7 @@ func readOne(r io.Reader) (*Buffer, error) {
|
||||
}
|
||||
}
|
||||
|
||||
b.Release()
|
||||
return nil, newError("Reader returns too many empty payloads.")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user