//TODO implement the logic func (r *Router) DealMsg(m Msg, reply *string) (err error) { log.Println("recv post msg", m) conns, err := getConnectors(m.Roomid) if err != nil { log.Println("get connectors addrs error", err) return err } data, err := json.Marshal(m) if err != nil { log.Println(" json marshal error:%v", err) return err } b := &BroadcastInfo{Roomid: m.Roomid, Msg: data} log.Println("start rpc call connector broadcast", m) for _, connAddr := range conns { client, err := rpc_pool.GetRpcClient(connAddr) if err != nil { log.Println("get rpc client error", err) continue } err = client.Call("RoomCenter.Broadcast", b, &reply) if err != nil { log.Println("rpc broadcast error:", err) *reply = "error" } log.Println("rpc result", *reply) } *reply = "OK" return }
// use *connectorInfo as 0-1 buf //TODO lock the map ? or pay attention to the gc func updateConn() { temp := new(map[string][]RoomInfo) conns := getConnectos() for _, conn_addr := range conns { client, err := rpc_pool.GetRpcClient(conn_addr.RpcAddr) if err != nil { log.Println("get rpc client error", err) continue } var reply []RoomInfo err = client.Call("RoomCenter.RoomInfo", "", &reply) if err != nil { log.Println("rpc broadcast error:", err) continue } (*temp)[conn_addr.ServeAddr] = reply log.Println("rpc result", reply) } connectorInfo = temp }