Commit 9a265ed1 authored by AlexStocks's avatar AlexStocks

forbid close udp session in OnCron

parent 2ec937f9
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
## develop history ## ## develop history ##
--- ---
- 2018/03/16
> bug fix
* forbid close udp session in OnCron
- 2018/03/14 - 2018/03/14
> init > init
......
...@@ -161,23 +161,24 @@ func (this *EchoMessageHandler) OnMessage(session getty.Session, udpCtx interfac ...@@ -161,23 +161,24 @@ func (this *EchoMessageHandler) OnMessage(session getty.Session, udpCtx interfac
func (this *EchoMessageHandler) OnCron(session getty.Session) { func (this *EchoMessageHandler) OnCron(session getty.Session) {
var ( var (
flag bool //flag bool
active time.Time active time.Time
) )
this.rwlock.RLock() this.rwlock.RLock()
if _, ok := this.sessionMap[session]; ok { if _, ok := this.sessionMap[session]; ok {
active = session.GetActive() active = session.GetActive()
if conf.sessionTimeout.Nanoseconds() < time.Since(active).Nanoseconds() { if conf.sessionTimeout.Nanoseconds() < time.Since(active).Nanoseconds() {
flag = true //flag = true
log.Warn("session{%s} timeout{%s}, reqNum{%d}", log.Error("session{%s} timeout{%s}, reqNum{%d}",
session.Stat(), time.Since(active).String(), this.sessionMap[session].reqNum) session.Stat(), time.Since(active).String(), this.sessionMap[session].reqNum)
} }
} }
this.rwlock.RUnlock() this.rwlock.RUnlock()
if flag { // udp session是根据本地udp socket fd生成的,如果关闭则连同socket也一同关闭了
this.rwlock.Lock() //if flag {
delete(this.sessionMap, session) // this.rwlock.Lock()
this.rwlock.Unlock() // delete(this.sessionMap, session)
session.Close() // this.rwlock.Unlock()
} // session.Close()
//}
} }
...@@ -6,7 +6,8 @@ AppName = "ECHO-SERVER" ...@@ -6,7 +6,8 @@ AppName = "ECHO-SERVER"
Host = "127.0.0.1" Host = "127.0.0.1"
# Host = "192.168.35.1" # Host = "192.168.35.1"
# Host = "192.168.8.3" # Host = "192.168.8.3"
Ports = ["10000", "20000"] # Ports = ["10000", "20000"]
Ports = ["10000"]
ProfilePort = 10086 ProfilePort = 10086
# session # session
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment