예제 #1
0
파일: router.go 프로젝트: nevermatch/goim
func genSubKey(userId int64) (res map[int32][]string) {
	var (
		i      int
		ok     bool
		key    string
		keys   []string
		client *rpc.Client
		err    error
		arg    = &rproto.GetArg{UserId: userId}
		reply  = &rproto.GetReply{}
	)
	res = make(map[int32][]string)
	if client, err = getRouterByUID(userId); err != nil {
		return
	}
	if err = client.Call(routerServiceGet, arg, reply); err != nil {
		log.Error("client.Call(\"%s\",\"%v\") error(%s)", routerServiceGet, arg, err)
		return
	}
	for i = 0; i < len(reply.Servers); i++ {
		key = encode(userId, reply.Seqs[i])
		if keys, ok = res[reply.Servers[i]]; !ok {
			keys = []string{}
		}
		keys = append(keys, key)
		res[reply.Servers[i]] = keys
	}
	return
}
예제 #2
0
func testSendDeadlock(client *protorpc.Client) {
	defer func() {
		recover()
	}()
	args := &Args{7, 8}
	reply := new(Reply)
	client.Call("Arith.Add", args, reply)
}
예제 #3
0
파일: comet.go 프로젝트: dulumao/goim
func broadcastRoomComet(c *protorpc.Client, roomId int32, msg []byte) {
	var (
		args = &cproto.BoardcastRoomArg{Ver: 0, Operation: define.OP_SEND_SMS_REPLY, Msg: msg, RoomId: roomId}
		err  error
	)
	if err = c.Call(CometServiceBroadcastRoom, args, nil); err != nil {
		log.Error("c.Call(\"%s\", %v, reply) error(%v)", CometServiceBroadcastRoom, *args, err)
	}
}
예제 #4
0
파일: comet.go 프로젝트: dulumao/goim
func mpushComet(c *protorpc.Client, subkeys []string, body []byte) {
	var (
		args = &cproto.MPushMsgArg{Keys: subkeys, Operation: define.OP_SEND_SMS_REPLY, Msg: body}
		rep  = &cproto.MPushMsgReply{}
		err  error
	)
	if err = c.Call(CometServiceMPushMsg, args, rep); err != nil {
		log.Error("c.Call(\"%s\", %v, reply) error(%v)", CometServiceMPushMsg, *args, err)
	}
}
예제 #5
0
파일: comet.go 프로젝트: dulumao/goim
func roomsComet(c *protorpc.Client) map[int32]bool {
	var (
		reply = &cproto.RoomsReply{}
		err   error
	)
	if err = c.Call(CometServiceRooms, nil, reply); err != nil {
		log.Error("c.Call(\"%s\", nil, reply) error(%v)", CometServiceRooms, err)
		return nil
	}
	return reply.Rooms
}
예제 #6
0
파일: router.go 프로젝트: huweixuan/goim
func getAllSubkeys(serverId string) (reply *rproto.GetAllReply, err error) {
	var client *rpc.Client
	if client, err = getRouterByServer(serverId); err != nil {
		return
	}
	reply = &rproto.GetAllReply{}
	if err = client.Call(routerServiceGetAll, nil, reply); err != nil {
		log.Error("client.Call(\"%s\") error(%s)", routerServiceGetAll, err)
	}
	return
}
예제 #7
0
파일: router.go 프로젝트: james4e/goim
func allRoomCount(client *rpc.Client) (counter map[int32]int32, err error) {
	var (
		reply = &rproto.AllRoomCountReply{}
	)
	if err = client.Call(routerServiceAllRoomCount, nil, reply); err != nil {
		log.Error("c.Call(\"%s\", nil) error(%v)", routerServiceAllRoomCount, err)
	} else {
		counter = reply.Counter
	}
	return
}
예제 #8
0
func getSubkeys(serverId string, userIds []int64) (reply *rproto.MGetReply, err error) {
	var client *rpc.Client
	if client, err = getRouterByServer(serverId); err != nil {
		return
	}
	arg := &rproto.MGetArg{UserIds: userIds}
	reply = &rproto.MGetReply{}
	if err = client.Call(routerServiceMGet, arg, reply); err != nil {
		log.Error("client.Call(\"%s\",\"%v\") error(%s)", routerServiceMGet, arg, err)
	}
	return
}
예제 #9
0
파일: comet.go 프로젝트: 1d7500/goim
func broadcastRoomComet(c *protorpc.Client, roomId int32, msg []byte) {
	var (
		now  = time.Now()
		args = &cproto.BoardcastRoomArg{Ver: 0, Operation: define.OP_SEND_SMS_REPLY, Msg: msg, RoomId: roomId}
		err  error
	)
	if err = c.Call(CometServiceBroadcastRoom, args, nil); err != nil {
		log.Error("c.Call(\"%s\", %v, reply) error(%v)", CometServiceBroadcastRoom, *args, err)
	} else {
		log.Info("broadcast msg to msg:%s room:%d(%f)", msg, roomId, time.Now().Sub(now).Seconds())
	}
}
예제 #10
0
파일: push_job.go 프로젝트: huweixuan/goim
func pushToComet(serverId int32, c *protorpc.Client, subkeys []string, body []byte, wg *sync.WaitGroup) {
	now := time.Now()
	args := &cproto.MPushMsgArg{Keys: subkeys, Operation: OP_SEND_SMS_REPLY, Msg: body}
	rep := &cproto.MPushMsgReply{}
	if err := c.Call(CometServiceMPushMsg, args, rep); err != nil {
		log.Error("c.Call(\"%s\", %v, reply) error(%v)", CometServiceMPushMsg, *args, err)
		goto done
	}
	log.Info("push msg to serverId:%d index:%d", serverId, rep.Index)
	log.Debug("push seconds %f", time.Now().Sub(now).Seconds())
done:
	wg.Done()
}
예제 #11
0
파일: comet.go 프로젝트: 1d7500/goim
func mpushComet(c *protorpc.Client, subkeys []string, body []byte) {
	var (
		now  = time.Now()
		args = &cproto.MPushMsgArg{Keys: subkeys, Operation: define.OP_SEND_SMS_REPLY, Msg: body}
		rep  = &cproto.MPushMsgReply{}
		err  error
	)
	if err = c.Call(CometServiceMPushMsg, args, rep); err != nil {
		log.Error("c.Call(\"%s\", %v, reply) error(%v)", CometServiceMPushMsg, *args, err)
	} else {
		log.Info("push msg to index:%d(%f)", rep.Index, time.Now().Sub(now).Seconds())
	}
}
예제 #12
0
파일: router.go 프로젝트: nevermatch/goim
func disconnect(userID int64, seq int32) (has bool, err error) {
	var client *rpc.Client
	if client, err = getRouterByUID(userID); err != nil {
		return
	}
	arg := &rproto.DisconnArg{UserId: userID, Seq: seq}
	reply := &rproto.DisconnReply{}
	if err = client.Call(routerServiceDisconnect, arg, reply); err != nil {
		log.Error("c.Call(\"%s\",\"%v\") error(%s)", routerServiceDisconnect, *arg, err)
	} else {
		has = reply.Has
	}
	return
}
예제 #13
0
파일: router.go 프로젝트: nevermatch/goim
func connect(userID int64, server int32) (seq int32, err error) {
	var client *rpc.Client
	if client, err = getRouterByUID(userID); err != nil {
		return
	}
	arg := &rproto.ConnArg{UserId: userID, Server: server}
	reply := &rproto.ConnReply{}
	if err = client.Call(routerServiceConnect, arg, reply); err != nil {
		log.Error("c.Call(\"%s\",\"%v\") error(%s)", routerServiceConnect, arg, err)
	} else {
		seq = reply.Seq
	}
	return
}
예제 #14
0
파일: router.go 프로젝트: dulumao/goim
func disconnect(userID int64, seq, roomId int32) (has bool, err error) {
	var (
		client *rpc.Client
		arg    = &rproto.DelArg{UserId: userID, Seq: seq, RoomId: roomId}
		reply  = &rproto.DelReply{}
	)
	if client, err = getRouterByUID(userID); err != nil {
		return
	}
	if err = client.Call(routerServiceDel, arg, reply); err != nil {
		log.Error("c.Call(\"%s\",\"%v\") error(%v)", routerServiceDel, *arg, err)
	} else {
		has = reply.Has
	}
	return
}
예제 #15
0
파일: logic.go 프로젝트: sf100/goim
func rpcPing(addr string, c *protorpc.Client, retry time.Duration) {
	var err error
	for {
		if err = c.Call(logicServicePing, nil, nil); err != nil {
			log.Error("c.Call(\"%s\", nil, nil) error(%v), retry after:%ds", logicServicePing, err, retry/time.Second)
			rpcTmp, err := protorpc.Dial("tcp", addr)
			if err != nil {
				log.Error("protorpc.Dial(\"tcp\", %s) error(%v)", addr, err)
				time.Sleep(retry)
				continue
			}
			c = rpcTmp
			time.Sleep(retry)
			continue
		}
		log.Debug("rpc ping:%s ok", addr)
		time.Sleep(retry)
		continue
	}
}
예제 #16
0
func testHTTPRPC(t *testing.T, path string) {
	var client *protorpc.Client
	var err error
	if path == "" {
		client, err = protorpc.DialHTTP("tcp", httpServerAddr)
	} else {
		client, err = protorpc.DialHTTPPath("tcp", httpServerAddr, path)
	}
	if err != nil {
		t.Fatal("dialing", err)
	}
	defer client.Close()

	// Synchronous calls
	args := &Args{7, 8}
	reply := new(Reply)
	err = client.Call("Arith.Add", args, reply)
	if err != nil {
		t.Errorf("Add: expected no error but got string %q", err.Error())
	}
	if reply.C != args.A+args.B {
		t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B)
	}
}