mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
cleanup
This commit is contained in:
parent
74830b2583
commit
53f99ddde6
@ -37,7 +37,7 @@ type ChunkStreamReader struct {
|
||||
|
||||
buffer []byte
|
||||
leftOver buf.MultiBuffer
|
||||
leftOverSize uint16
|
||||
leftOverSize int
|
||||
}
|
||||
|
||||
func NewChunkStreamReader(sizeDecoder ChunkSizeDecoder, reader io.Reader) *ChunkStreamReader {
|
||||
@ -50,6 +50,7 @@ func NewChunkStreamReader(sizeDecoder ChunkSizeDecoder, reader io.Reader) *Chunk
|
||||
|
||||
func (r *ChunkStreamReader) readAtLeast(size int) error {
|
||||
mb := r.leftOver
|
||||
r.leftOver = nil
|
||||
for mb.Len() < size {
|
||||
extra, err := r.reader.Read()
|
||||
if err != nil {
|
||||
@ -74,7 +75,7 @@ func (r *ChunkStreamReader) readSize() (uint16, error) {
|
||||
}
|
||||
|
||||
func (r *ChunkStreamReader) Read() (buf.MultiBuffer, error) {
|
||||
size := int(r.leftOverSize)
|
||||
size := r.leftOverSize
|
||||
if size == 0 {
|
||||
nextSize, err := r.readSize()
|
||||
if err != nil {
|
||||
@ -94,7 +95,7 @@ func (r *ChunkStreamReader) Read() (buf.MultiBuffer, error) {
|
||||
|
||||
if size >= r.leftOver.Len() {
|
||||
mb := r.leftOver
|
||||
r.leftOverSize = uint16(size - r.leftOver.Len())
|
||||
r.leftOverSize = size - r.leftOver.Len()
|
||||
r.leftOver = nil
|
||||
return mb, nil
|
||||
}
|
||||
|
@ -647,12 +647,12 @@ func TestVMessNone(t *testing.T) {
|
||||
payload := make([]byte, 10240*1024)
|
||||
rand.Read(payload)
|
||||
|
||||
nBytes, err := conn.Write([]byte(payload))
|
||||
nBytes, err := conn.Write(payload)
|
||||
assert.Error(err).IsNil()
|
||||
assert.Int(nBytes).Equals(len(payload))
|
||||
|
||||
response := readFrom(conn, time.Second*20, 10240*1024)
|
||||
assert.Bytes(response).Equals(xor([]byte(payload)))
|
||||
assert.Bytes(response).Equals(xor(payload))
|
||||
assert.Error(conn.Close()).IsNil()
|
||||
wg.Done()
|
||||
}()
|
||||
|
Loading…
Reference in New Issue
Block a user