|
@@ -3,7 +3,6 @@ package mqtt
|
|
|
import (
|
|
|
"encoding/hex"
|
|
|
"errors"
|
|
|
- "fmt"
|
|
|
"net"
|
|
|
"sparrow/pkg/models"
|
|
|
"sparrow/pkg/rpcs"
|
|
@@ -309,17 +308,16 @@ func (c *Connection) RcvMsgFromClient() {
|
|
|
func (c *Connection) SendMsgToClient() {
|
|
|
host := c.Conn.RemoteAddr()
|
|
|
for {
|
|
|
+ c.lock.Lock()
|
|
|
+ if c.SendChan == nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
msg, ok := <-c.SendChan
|
|
|
if !ok {
|
|
|
server.Log.Errorf("%s is end now", host)
|
|
|
return
|
|
|
}
|
|
|
- c.lock.Lock()
|
|
|
-
|
|
|
server.Log.Debugf("send msg to %s=======\n%v\n=========", host, msg)
|
|
|
- if c.Conn == nil {
|
|
|
- fmt.Printf("客户端实例:%v, 消息内容:%v\r\n", c.Conn, msg)
|
|
|
- }
|
|
|
err := msg.Encode(c.Conn)
|
|
|
if err != nil {
|
|
|
server.Log.Errorf("send msg err: %s=====\n%v\n=====", err, msg)
|