fix write logic

This commit is contained in:
zhouyuyan
2018-04-28 09:37:37 +08:00
parent 56fb4a2d54
commit 684584b208

View File

@@ -3,6 +3,7 @@
package broker
import (
"errors"
"net"
"reflect"
"strings"
@@ -498,9 +499,11 @@ func (c *client) Close() {
c.smu.Unlock()
return
}
c.status = Disconnected
//wait for message complete
time.Sleep(1 * time.Second)
c.status = Disconnected
// c.status = Disconnected
if c.conn != nil {
c.conn.Close()
@@ -540,10 +543,18 @@ func (c *client) Close() {
}
func (c *client) WriterPacket(packet packets.ControlPacket) error {
if c == nil || packet == nil {
if c.status == Disconnected {
return nil
}
if packet == nil {
return nil
}
if c.conn == nil {
c.Close()
return errors.New("connect lost ....")
}
c.mu.Lock()
err := packet.Write(c.conn)
c.mu.Unlock()