Пример #1
0
func newFrontLink(session *link.Session, linkID uint64) *frontendLink {
	flink := &frontendLink{
		session:     session,
		linkId:      linkID,
		clients:     make(map[uint64]*link.Session),
		clientWaits: make(map[uint64]*link.Session),
	}

	session.AddCloseCallback(flink, func() {
		flink.Close()
	})

	go func() {
		var msg = gatewayMsg{}
		for {
			if err := session.Receive(&msg); err != nil {
				break
			}
			switch msg.Command {
			case CMD_MSG:
				flink.dispathMsg(msg.ClientId, msg.Data)
			case CMD_BRD:
				flink.broadcast(msg.ClientIds, msg.Data)
			case CMD_NEW_2:
				flink.newClient(msg.ClientId, msg.ClientIds[0])
			case CMD_DEL:
				flink.delClient(msg.ClientId, false)
			}
		}
		flink.Close()
	}()

	return flink
}
Пример #2
0
func sessionReceive(session *link.Session, d dispatch.DispatchInterface) {
	for {
		var msg []byte
		if err := session.Receive(&msg); err != nil {
			break
		}

		d.Process(session, msg)
	}
}
Пример #3
0
func BytesTest(t *testing.T, session *link.Session) {
	for i := 0; i < 2000; i++ {
		msg1 := RandBytes(512)
		err := session.Send(msg1)
		unitest.NotError(t, err)

		var msg2 []byte
		err = session.Receive(&msg2)
		unitest.NotError(t, err)
		unitest.Pass(t, bytes.Equal(msg1, msg2))
	}
}
Пример #4
0
func ObjectTest(t *testing.T, session *link.Session) {
	for i := 0; i < 2000; i++ {
		msg1 := RandObject()
		err := session.Send(&msg1)
		unitest.NotError(t, err)

		var msg2 TestObject
		err = session.Receive(&msg2)
		unitest.NotError(t, err)
		unitest.Pass(t, msg1 == msg2)
	}
}
Пример #5
0
func StringTest(t *testing.T, session *link.Session) {
	for i := 0; i < 2000; i++ {
		msg1 := string(RandBytes(512))
		err := session.Send(msg1)
		unitest.NotError(t, err)

		var msg2 string
		err = session.Receive(&msg2)
		unitest.NotError(t, err)
		unitest.Pass(t, msg1 == msg2)
	}
}
Пример #6
0
//开始处理游戏逻辑消息
func startDealReceiveMsgC2S(session *link.Session) {
	revMsgChan := make(chan *packet.RAW, 2048)
	go func() {
		for {
			data, ok := <-revMsgChan
			if !ok {
				return
			}
			dealReceiveMsgC2S(session, *data)
		}
	}()

	for {
		var msg packet.RAW
		if err := session.Receive(&msg); err != nil {
			break
		}
		revMsgChan <- &msg
	}
}