1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-30 05:56:54 -05:00

Fix ending in vmess reader.

This commit is contained in:
v2ray 2016-05-05 00:24:18 +02:00
parent a7f61af79b
commit 0bc846f016
3 changed files with 14 additions and 9 deletions

View File

@ -129,6 +129,8 @@ func (this *DokodemoDoor) HandleTCPConnection(conn *hub.Connection) {
outputFinish.Lock()
reader := v2net.NewTimeOutReader(this.config.Timeout, conn)
defer reader.Release()
go func() {
v2reader := v2io.NewAdaptiveReader(reader)
defer v2reader.Release()
@ -147,4 +149,5 @@ func (this *DokodemoDoor) HandleTCPConnection(conn *hub.Connection) {
}()
outputFinish.Lock()
inputFinish.Lock()
}

View File

@ -62,12 +62,6 @@ func (this *AuthChunkReader) Read() (*alloc.Buffer, error) {
buffer = AllocBuffer(this.chunkLength).Clear()
}
_, err := buffer.FillFrom(this.reader)
if err != nil {
buffer.Release()
return nil, err
}
if this.chunkLength == -1 {
for buffer.Len() < 6 {
_, err := buffer.FillFrom(this.reader)
@ -80,6 +74,12 @@ func (this *AuthChunkReader) Read() (*alloc.Buffer, error) {
this.chunkLength = int(length) - 4
this.validator = NewValidator(serial.BytesLiteral(buffer.Value[2:6]).Uint32Value())
buffer.SliceFrom(6)
} else if buffer.Len() < this.chunkLength {
_, err := buffer.FillFrom(this.reader)
if err != nil {
buffer.Release()
return nil, err
}
}
if this.chunkLength == 0 {

View File

@ -1,6 +1,8 @@
package scenarios
import (
"bytes"
"io"
"net"
"testing"
@ -42,10 +44,10 @@ func TestDynamicVMess(t *testing.T) {
conn.CloseWrite()
response := make([]byte, 1024)
nBytes, err = conn.Read(response)
response := bytes.NewBuffer(nil)
_, err = io.Copy(response, conn)
assert.Error(err).IsNil()
assert.StringLiteral("Processed: " + payload).Equals(string(response[:nBytes]))
assert.StringLiteral("Processed: " + payload).Equals(string(response.Bytes()))
conn.Close()
}