From 566adec285b67a932b4c46d6e858d7767a20b417 Mon Sep 17 00:00:00 2001 From: v2ray Date: Mon, 11 Jul 2016 15:46:18 +0200 Subject: [PATCH] allow customized timeout in socks protocol --- proxy/socks/config.go | 1 + proxy/socks/config_json.go | 5 +++++ proxy/socks/server.go | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/proxy/socks/config.go b/proxy/socks/config.go index d86149dad..c560908bb 100644 --- a/proxy/socks/config.go +++ b/proxy/socks/config.go @@ -14,6 +14,7 @@ type Config struct { Accounts map[string]string Address v2net.Address UDPEnabled bool + Timeout int } func (this *Config) HasAccount(username, password string) bool { diff --git a/proxy/socks/config_json.go b/proxy/socks/config_json.go index 8014aa2cf..73b2af91f 100644 --- a/proxy/socks/config_json.go +++ b/proxy/socks/config_json.go @@ -27,6 +27,7 @@ func (this *Config) UnmarshalJSON(data []byte) error { Accounts []*SocksAccount `json:"accounts"` UDP bool `json:"udp"` Host *v2net.AddressJson `json:"ip"` + Timeout int `json:"timeout"` } rawConfig := new(SocksConfig) @@ -55,6 +56,10 @@ func (this *Config) UnmarshalJSON(data []byte) error { } else { this.Address = v2net.LocalHostIP } + + if rawConfig.Timeout >= 0 { + this.Timeout = rawConfig.Timeout + } return nil } diff --git a/proxy/socks/server.go b/proxy/socks/server.go index a516c8cd9..a39d00746 100644 --- a/proxy/socks/server.go +++ b/proxy/socks/server.go @@ -96,7 +96,7 @@ func (this *Server) Start() error { func (this *Server) handleConnection(connection internet.Connection) { defer connection.Close() - timedReader := v2net.NewTimeOutReader(120, connection) + timedReader := v2net.NewTimeOutReader(this.config.Timeout, connection) reader := v2io.NewBufferedReader(timedReader) defer reader.Release()