1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00

KCP: delay conn close to prevent conn leak

This commit is contained in:
Shelikhoo 2016-06-13 07:08:40 +08:00
parent 4df5d42011
commit 9144b66217
No known key found for this signature in database
GPG Key ID: 7791BDB0709ABD21

View File

@ -74,6 +74,8 @@ type KCPVconn struct {
conntokeep time.Time
}
var counter int
func (kcpvc *KCPVconn) Read(b []byte) (int, error) {
ifb := time.Now().Add(time.Duration(kcpvc.conf.AdvancedConfigs.ReadTimeout) * time.Second)
if ifb.After(kcpvc.conntokeep) {
@ -114,12 +116,19 @@ func (kcpvc *KCPVconn) ApplyConf() error {
kcpvc.hc.SetMtu(kcpvc.conf.AdvancedConfigs.Mtu)
kcpvc.hc.SetACKNoDelay(kcpvc.conf.AdvancedConfigs.Acknodelay)
kcpvc.hc.SetDSCP(kcpvc.conf.AdvancedConfigs.Dscp)
//counter++
//log.Info(counter)
return nil
}
func (kcpvc *KCPVconn) Close() error {
return kcpvc.hc.Close()
go func() {
time.Sleep(2000 * time.Millisecond)
//counter--
//log.Info(counter)
kcpvc.hc.Close()
}()
return nil
}
func (kcpvc *KCPVconn) LocalAddr() net.Addr {