Fix connection reuse

pull/168/head
v2ray 2016-06-02 02:20:53 +02:00
parent a86cd36ad2
commit dfe1ac1f2b
7 changed files with 25 additions and 15 deletions

View File

@ -170,7 +170,7 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
requestReader = v2io.NewAdaptiveReader(bodyReader) requestReader = v2io.NewAdaptiveReader(bodyReader)
} }
err := v2io.Pipe(requestReader, input) err := v2io.Pipe(requestReader, input)
if err != vmessio.ErrorStreamCompleted { if err != io.EOF {
connection.SetReusable(false) connection.SetReusable(false)
} }
@ -202,7 +202,7 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
writer.SetCached(false) writer.SetCached(false)
err = v2io.Pipe(output, v2writer) err = v2io.Pipe(output, v2writer)
if err != vmessio.ErrorStreamCompleted { if err != io.EOF {
connection.SetReusable(false) connection.SetReusable(false)
} }

View File

@ -1,7 +1,6 @@
package io package io
import ( import (
"errors"
"hash" "hash"
"hash/fnv" "hash/fnv"
"io" "io"
@ -11,10 +10,6 @@ import (
"github.com/v2ray/v2ray-core/transport" "github.com/v2ray/v2ray-core/transport"
) )
var (
ErrorStreamCompleted = errors.New("Stream completed.")
)
// @Private // @Private
type Validator struct { type Validator struct {
actualAuth hash.Hash32 actualAuth hash.Hash32
@ -81,7 +76,7 @@ func (this *AuthChunkReader) Read() (*alloc.Buffer, error) {
if this.chunkLength == 0 { if this.chunkLength == 0 {
buffer.Release() buffer.Release()
return nil, ErrorStreamCompleted return nil, io.EOF
} }
if buffer.Len() < this.chunkLength { if buffer.Len() < this.chunkLength {

View File

@ -1,6 +1,7 @@
package outbound package outbound
import ( import (
"io"
"sync" "sync"
"github.com/v2ray/v2ray-core/app" "github.com/v2ray/v2ray-core/app"
@ -85,7 +86,7 @@ func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn
writer.SetCached(false) writer.SetCached(false)
err := v2io.Pipe(input, streamWriter) err := v2io.Pipe(input, streamWriter)
if err != vmessio.ErrorStreamCompleted { if err != io.EOF {
conn.SetReusable(false) conn.SetReusable(false)
} }
@ -120,7 +121,7 @@ func (this *VMessOutboundHandler) handleResponse(session *raw.ClientSession, con
} }
err = v2io.Pipe(bodyReader, output) err = v2io.Pipe(bodyReader, output)
if err != vmessio.ErrorStreamCompleted { if err != io.EOF {
conn.SetReusable(false) conn.SetReusable(false)
} }

View File

@ -29,5 +29,11 @@
} }
] ]
} }
},
"transport": {
"streamType": "tcp",
"settings": {
"connectionReuse": true
}
} }
} }

View File

@ -38,5 +38,11 @@
"refresh": 5 "refresh": 5
} }
} }
] ],
"transport": {
"streamType": "tcp",
"settings": {
"connectionReuse": true
}
}
} }

View File

@ -21,10 +21,12 @@ func (this *Config) UnmarshalJSON(data []byte) error {
return err return err
} }
this.StreamType = StreamTypeTCP
streamType := strings.ToLower(typeConfig.StreamType) streamType := strings.ToLower(typeConfig.StreamType)
if streamType == "tcp" { if streamType == "tcp" {
jsonTCPConfig := new(JsonTCPConfig) jsonTCPConfig := new(JsonTCPConfig)
if err := json.Unmarshal(data, jsonTCPConfig); err != nil { if err := json.Unmarshal(typeConfig.Settings, jsonTCPConfig); err != nil {
return err return err
} }
this.TCPConfig = &TCPConfig{ this.TCPConfig = &TCPConfig{

View File

@ -3,7 +3,7 @@ package transport
import "github.com/v2ray/v2ray-core/common/log" import "github.com/v2ray/v2ray-core/common/log"
var ( var (
TCPStreamConfig = &TCPConfig{ TCPStreamConfig = TCPConfig{
ConnectionReuse: false, ConnectionReuse: false,
} }
) )
@ -11,8 +11,8 @@ var (
func ApplyConfig(config *Config) error { func ApplyConfig(config *Config) error {
if config.StreamType == StreamTypeTCP { if config.StreamType == StreamTypeTCP {
if config.TCPConfig != nil { if config.TCPConfig != nil {
TCPStreamConfig = config.TCPConfig TCPStreamConfig.ConnectionReuse = config.TCPConfig.ConnectionReuse
if config.TCPConfig.ConnectionReuse { if TCPStreamConfig.ConnectionReuse {
log.Info("Transport: TCP connection reuse enabled.") log.Info("Transport: TCP connection reuse enabled.")
} }
} }