liuxiaolong
2021-01-30 3513eea6ac7049e696d6c1a6e7f2120a7f2529c5
不用mtxWorker锁,sendandrecv是线程安全的
1个文件已修改
14 ■■■■ 已修改文件
hbusc.go 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hbusc.go
@@ -48,7 +48,7 @@
    sockSub *sockClient  //订阅主题的socket,线程实时接收消息,需要单独处理
    sockWorker     *sockClient  //发给任意的server,短暂的request client
    mtxWorker     sync.Mutex     //SendAndRecv可能不是线程安全的
    //mtxWorker     sync.Mutex     //SendAndRecv可能不是线程安全的
    chSub chan TransInfo
    chReply chan TransInfo
@@ -273,8 +273,8 @@
        return err
    }
    h.mtxWorker.Lock()
    defer h.mtxWorker.Unlock()
    //h.mtxWorker.Lock()
    //defer h.mtxWorker.Unlock()
    netNodes := append([]bhomebus.NetNode{}, bhomebus.NetNode{
        Key: h.conf.regKey,
    })
@@ -490,8 +490,8 @@
    if err != nil {
        return err
    }
    h.mtxWorker.Lock()
    defer h.mtxWorker.Unlock()
    //h.mtxWorker.Lock()
    //defer h.mtxWorker.Unlock()
    n := h.sockWorker.sock.SendtoTimeout(data, key, h.conf.sendTimeOut)
    if n != 0 {
        return fmt.Errorf("sendOnly ret n:%d", n)
@@ -507,8 +507,8 @@
    rNodes := append([]bhomebus.NetNode{}, bhomebus.NetNode{
        Key: KEY_QUERY,
    })
    h.mtxWorker.Lock()
    defer h.mtxWorker.Unlock()
    //h.mtxWorker.Lock()
    //defer h.mtxWorker.Unlock()
    var ret []bhomebus.Mesg
    n := h.sockWorker.sock.SendandrecvTimeout(rNodes, data,&ret, h.conf.sendTimeOut)
    h.printLog("requestCenter n:", n, "len(ret):", len(ret))