mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 18:17:52 -05:00
KCP: delay conn close to prevent conn leak
This commit is contained in:
parent
4df5d42011
commit
9144b66217
@ -74,6 +74,8 @@ type KCPVconn struct {
|
|||||||
conntokeep time.Time
|
conntokeep time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var counter int
|
||||||
|
|
||||||
func (kcpvc *KCPVconn) Read(b []byte) (int, error) {
|
func (kcpvc *KCPVconn) Read(b []byte) (int, error) {
|
||||||
ifb := time.Now().Add(time.Duration(kcpvc.conf.AdvancedConfigs.ReadTimeout) * time.Second)
|
ifb := time.Now().Add(time.Duration(kcpvc.conf.AdvancedConfigs.ReadTimeout) * time.Second)
|
||||||
if ifb.After(kcpvc.conntokeep) {
|
if ifb.After(kcpvc.conntokeep) {
|
||||||
@ -114,12 +116,19 @@ func (kcpvc *KCPVconn) ApplyConf() error {
|
|||||||
kcpvc.hc.SetMtu(kcpvc.conf.AdvancedConfigs.Mtu)
|
kcpvc.hc.SetMtu(kcpvc.conf.AdvancedConfigs.Mtu)
|
||||||
kcpvc.hc.SetACKNoDelay(kcpvc.conf.AdvancedConfigs.Acknodelay)
|
kcpvc.hc.SetACKNoDelay(kcpvc.conf.AdvancedConfigs.Acknodelay)
|
||||||
kcpvc.hc.SetDSCP(kcpvc.conf.AdvancedConfigs.Dscp)
|
kcpvc.hc.SetDSCP(kcpvc.conf.AdvancedConfigs.Dscp)
|
||||||
|
//counter++
|
||||||
|
//log.Info(counter)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kcpvc *KCPVconn) Close() error {
|
func (kcpvc *KCPVconn) Close() error {
|
||||||
|
go func() {
|
||||||
return kcpvc.hc.Close()
|
time.Sleep(2000 * time.Millisecond)
|
||||||
|
//counter--
|
||||||
|
//log.Info(counter)
|
||||||
|
kcpvc.hc.Close()
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kcpvc *KCPVconn) LocalAddr() net.Addr {
|
func (kcpvc *KCPVconn) LocalAddr() net.Addr {
|
||||||
|
Loading…
Reference in New Issue
Block a user