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

View File

@@ -86,11 +86,11 @@ func (b *Broker) Start() {
func StateMonitor() {
v, _ := mem.VirtualMemory()
timeSticker := time.NewTicker(time.Second * 5)
timeSticker := time.NewTicker(time.Second * 30)
for {
select {
case <-timeSticker.C:
if v.UsedPercent > 0.8 {
if v.UsedPercent > 75 {
debug.FreeOSMemory()
}
// fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent)

View File

@@ -467,13 +467,19 @@ func (c *client) ProcessPing() {
}
func (c *client) Close() {
if c.status == Disconnected {
return
}
c.smu.Lock()
c.status = Disconnected
c.smu.Unlock()
if c.conn != nil {
c.conn.Close()
c.conn = nil
}
c.smu.Unlock()
b := c.broker
subs := c.subs
if b != nil {