| | |
| | | func (h *BHBus) Request(serverId string, req *MsgInfo, milliSecs int) (*Reply, error) { |
| | | //1.首先需要通过topic拿到本机对应的NetNode |
| | | rNodes, err := h.GetNetNodeByTopic(serverId, &req.SrcProc, req.Topic) |
| | | h.printLog("topic", req.Topic, "rNodes:", rNodes, "err:", err) |
| | | if err != nil { |
| | | h.printLog("topic: ", req.Topic, " rNodes: ", rNodes, " err:", err) |
| | | return nil, err |
| | | } |
| | | if rNodes == nil || len(rNodes) == 0 { |
| | | return nil, errors.New("rNodes empty, topic: "+ req.Topic) |
| | | } |
| | | //2.将请求返送到对应的server,并等待返回值 |
| | | data, err := json.Marshal(*req) |
| | | h.printLog("marshal(*req) err:", err) |
| | | if err != nil { |
| | | h.printLog("marshal(*req) err:", err) |
| | | return nil, err |
| | | } |
| | | var ret []bhomebus.Mesg |
| | |
| | | } |
| | | } else { |
| | | h.printLog("Request n: ", n, " len(ret): ", len(ret)) |
| | | return nil, fmt.Errorf("request err, SendandrecvTimeout n:%d", n) |
| | | } |
| | | return nil, fmt.Errorf("request err") |
| | | } |
| | | |
| | | func (h *BHBus) RequestOnly(rData []byte, rNodes []bhomebus.NetNode) ([]byte, error) { |
| | |
| | | return ret[0].Data, nil |
| | | } else { |
| | | h.printLog("Request n: ", n, " len(ret): ", len(ret), "rData:", string(rData)) |
| | | return nil, fmt.Errorf("request err, SendandrecvTimeout n:%d", n) |
| | | } |
| | | return nil, fmt.Errorf("request err") |
| | | } |
| | | |
| | | func (h *BHBus) Reply(replyKey int, i *Reply) error { |