mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-08 14:29:42 +08:00
添加 空闲链接超时自动断开
This commit is contained in:
@@ -21,10 +21,13 @@ func LinkCstp(conn net.Conn, bufRW *bufio.ReadWriter, cSess *sessdata.ConnSessio
|
||||
}()
|
||||
|
||||
var (
|
||||
err error
|
||||
n int
|
||||
dataLen uint16
|
||||
dead = time.Duration(cSess.CstpDpd+5) * time.Second
|
||||
err error
|
||||
n int
|
||||
dataLen uint16
|
||||
dead = time.Second * time.Duration(cSess.CstpDpd+5)
|
||||
idle = time.Second * time.Duration(base.Cfg.IdleTimeout)
|
||||
checkIdle = base.Cfg.IdleTimeout > 0
|
||||
lastTime time.Time
|
||||
)
|
||||
|
||||
go cstpWrite(conn, bufRW, cSess)
|
||||
@@ -55,9 +58,19 @@ func LinkCstp(conn net.Conn, bufRW *bufio.ReadWriter, cSess *sessdata.ConnSessio
|
||||
case 0x07: // KEEPALIVE
|
||||
// do nothing
|
||||
// base.Debug("recv keepalive", cSess.IpAddr)
|
||||
// 判断超时时间
|
||||
if checkIdle {
|
||||
lastTime = cSess.LastDataTime.Load()
|
||||
if lastTime.Before(utils.NowSec().Add(-idle)) {
|
||||
base.Warn("IdleTimeout", cSess.Username, cSess.IpAddr, "lastTime", lastTime)
|
||||
sessdata.CloseSess(cSess.Sess.Token, dbdata.UserIdleTimeout)
|
||||
return
|
||||
}
|
||||
}
|
||||
case 0x05: // DISCONNECT
|
||||
cSess.UserLogoutCode = dbdata.UserLogoutClient
|
||||
base.Debug("DISCONNECT", cSess.Username, cSess.IpAddr)
|
||||
sessdata.CloseSess(cSess.Sess.Token, dbdata.UserLogoutClient)
|
||||
return
|
||||
case 0x03: // DPD-REQ
|
||||
// base.Debug("recv DPD-REQ", cSess.IpAddr)
|
||||
@@ -98,6 +111,8 @@ func LinkCstp(conn net.Conn, bufRW *bufio.ReadWriter, cSess *sessdata.ConnSessio
|
||||
if payloadIn(cSess, pl) {
|
||||
return
|
||||
}
|
||||
// 只记录返回正确的数据时间
|
||||
cSess.LastDataTime.Store(utils.NowSec())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user