mirror of
https://github.com/fhmq/hmq.git
synced 2026-04-26 11:38:33 +00:00
fix write logic
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user