mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
Fix connection reuse
This commit is contained in:
parent
a86cd36ad2
commit
dfe1ac1f2b
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -29,5 +29,11 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"transport": {
|
||||
"streamType": "tcp",
|
||||
"settings": {
|
||||
"connectionReuse": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,5 +38,11 @@
|
||||
"refresh": 5
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"transport": {
|
||||
"streamType": "tcp",
|
||||
"settings": {
|
||||
"connectionReuse": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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{
|
||||
|
@ -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.")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user