mirror of
https://github.com/jkstack/libagent.git
synced 2025-12-24 12:11:57 +08:00
连接断开时不进行状态上报
This commit is contained in:
7
app.go
7
app.go
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user