1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-27 22:36:12 -04:00

Fix connection reuse

This commit is contained in:
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)
}
err := v2io.Pipe(requestReader, input)
if err != vmessio.ErrorStreamCompleted {
if err != io.EOF {
connection.SetReusable(false)
}
@ -202,7 +202,7 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
writer.SetCached(false)
err = v2io.Pipe(output, v2writer)
if err != vmessio.ErrorStreamCompleted {
if err != io.EOF {
connection.SetReusable(false)
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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