连接断开时不进行状态上报

This commit is contained in:
lwch
2022-09-01 12:17:04 +08:00
parent faa454226a
commit a6fb417ddd
2 changed files with 8 additions and 2 deletions

7
app.go
View File

@@ -21,8 +21,9 @@ type app struct {
chWrite chan *anet.Msg
// runtime
ctx context.Context
cancel context.CancelFunc
ctx context.Context
cancel context.CancelFunc
connected bool
// monitor
inPackets, inBytes uint64
@@ -76,6 +77,7 @@ func (app *app) start() {
continue
}
app.connected = true
deferCallback("on_connect", app.a.OnConnect)
ctx, cancel := context.WithCancel(app.ctx)
@@ -85,6 +87,7 @@ func (app *app) start() {
<-ctx.Done()
app.connected = false
conn.Close()
deferCallback("dis_connect", app.a.OnDisconnect)

View File

@@ -13,6 +13,9 @@ import (
func (app *app) report() {
for {
time.Sleep(app.a.Configure().Monitor.Interval.Duration())
if !app.connected {
continue
}
app.a.OnReportMonitor()
app.chWrite <- app.buildReport()
}