disconnect

This commit is contained in:
zhouyuyan
2017-09-12 15:37:05 +08:00
parent 49385e52fd
commit 4646042b7f
2 changed files with 9 additions and 3 deletions
+2 -2
View File
@@ -86,11 +86,11 @@ func (b *Broker) Start() {
func StateMonitor() { func StateMonitor() {
v, _ := mem.VirtualMemory() v, _ := mem.VirtualMemory()
timeSticker := time.NewTicker(time.Second * 5) timeSticker := time.NewTicker(time.Second * 30)
for { for {
select { select {
case <-timeSticker.C: case <-timeSticker.C:
if v.UsedPercent > 0.8 { if v.UsedPercent > 75 {
debug.FreeOSMemory() debug.FreeOSMemory()
} }
// fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent) // fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent)
+7 -1
View File
@@ -467,13 +467,19 @@ func (c *client) ProcessPing() {
} }
func (c *client) Close() { func (c *client) Close() {
if c.status == Disconnected {
return
}
c.smu.Lock() c.smu.Lock()
c.status = Disconnected c.status = Disconnected
c.smu.Unlock()
if c.conn != nil { if c.conn != nil {
c.conn.Close() c.conn.Close()
c.conn = nil c.conn = nil
} }
c.smu.Unlock()
b := c.broker b := c.broker
subs := c.subs subs := c.subs
if b != nil { if b != nil {