Exemplo n.º 1
0
func (this *SClientUser) runImp() {
	defer bsn_common.FuncGuard()
	defer func() {
		this.Close()
		this.UserMgr().DelUser(this)
	}()

	vSServerUserMgr := this.UserMgr().Gate().GetServerMgr()
	var vMsg bsn_msg.SMsgHeaderGateClient
	for !this.M_bClose {
		err := this.ReadMsgHeader()
		if err != nil {
			GSLog.Errorln(err)
			break
		}
		GSLog.Debugln("recv this.M_byMsgHeader= ", this.M_byMsgHeader)
		vMsg.DeSerialize(this.M_byMsgHeader)
		GSLog.Debugln("recv vMsg= ", vMsg)

		vLen := vMsg.Len()
		if vLen < bsn_msg.CSMsgHeader_Size {
			GSLog.Errorln("error size")
			break
		}

		this.M_byMsgBody = make([]byte, vLen)
		err = this.ReadMsgBody()
		if err != nil {
			GSLog.Errorln(err)
			return
		}

		GSLog.Debugln("recv this.M_byMsgBody= ", this.M_byMsgBody)
		if vMsg.UserId() == 0 {
			vSMsgHeader := bsn_msg.NewMsgHeaderFromBytes(this.M_byMsgBody)
			GSLog.Debugln("recv vSMsgHeader= ", vSMsgHeader)
			GSLog.Debugln("recv msg= ", string(this.M_byMsgBody[int(unsafe.Sizeof(*vSMsgHeader)):]))
		} else {
			err = vSServerUserMgr.SendMsgToUser(vMsg.UserId(), this.M_byMsgBody)
			if err != nil {
				GSLog.Errorln("process msg err: ", vMsg.Type(), err)
			}
		}
	}
}
Exemplo n.º 2
0
Arquivo: session.go Projeto: bsn069/go
func (this *SSession) RecvMsgWithSMsgHeader() (bsn_common.TMsgType, []byte, error) {
	byMsgHeader := make([]byte, bsn_msg.CSMsgHeader_Size)
	err := this.Recv(byMsgHeader)
	if err != nil {
		return 0, nil, err
	}
	vSMsgHeader := bsn_msg.NewMsgHeaderFromBytes(byMsgHeader)

	vu16Len := uint16(vSMsgHeader.Len())
	if vu16Len > 0 {
		byData := make([]byte, vu16Len)
		err = this.Recv(byData)
		if err != nil {
			return vSMsgHeader.Type(), nil, err
		}
	}

	return vSMsgHeader.Type(), nil, nil
}