Ejemplo n.º 1
0
func P_talk_req(sess *Session, reader *packet.Packet) []byte {
	tbl, _ := PKT_talk(reader)
	dest := user_tbl.Query(tbl.F_user)
	chat := Words{tbl.F_msg, sess.User.Name}
	if dest != nil {
		ipc.Send(sess.User.Id, dest.Id, ipc.SVC_CHAT, &chat)
	} else {
		log.Println("no such user :", tbl.F_user)
	}
	return nil
}
Ejemplo n.º 2
0
func BenchmarkIPC(b *testing.B) {
	wg := &sync.WaitGroup{}

	for i := 1; i <= b.N; i++ {
		var sess Session
		sess.User = &User{Id: int32(i)}
		sess.MQ = make(chan IPCObject, 10)
		gsdb.RegisterOnline(&sess, sess.User.Id)
		go _simple_receiver(&sess, wg)
	}

	for i := 1; i <= b.N; i++ {
		src := rand.Int31n(int32(b.N)) + 1
		dest := rand.Int31n(int32(b.N)) + 1
		if src != dest {
			wg.Add(2)
			ipc.Send(src, dest, ipc.SERVICE_PING, false, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
		}
	}
	wg.Wait()
}
Ejemplo n.º 3
0
func TestIPC(t *testing.T) {
	// fake 2 user
	var sess1 Session
	sess1.User = &User{Id: 1}
	sess1.MQ = make(chan IPCObject, 10)
	var sess2 Session
	sess2.User = &User{Id: 2}
	sess2.MQ = make(chan IPCObject, 10)

	wg := &sync.WaitGroup{}
	wg.Add(2)
	go _simple_receiver(&sess1, wg)
	go _simple_receiver(&sess2, wg)

	gsdb.RegisterOnline(&sess1, sess1.User.Id)
	gsdb.RegisterOnline(&sess2, sess2.User.Id)

	if !ipc.Send(1, 2, ipc.SERVICE_PING, false, "ABC") {
		t.Fatal("ipc.Send failed")
	}
	wg.Wait()
}