Ejemplo n.º 1
0
func (client *Client) input() {
	var err error
	for err == nil {
		message, err := client.codec.ReadMessage()
		if err != nil &&
			!strings.Contains(err.Error(), "An existing connection was forcibly closed by the remote host") &&
			!strings.Contains(err.Error(), "use of closed network connection") {
			log.LogError(client.codec.GetAddress(), err)
			break
		}

		ar := util.NewLoadArchiver(message.Header)
		seq, err := ar.ReadUInt64()
		client.mutex.Lock()
		call := client.pending[seq]
		delete(client.pending, seq)
		client.mutex.Unlock()

		switch {
		case call == nil:
		default:
			call.Reply = message
			client.queue <- call
			log.LogDebug("response replyed, seq:", seq)
		}
	}
	// Terminate pending calls.
	client.mutex.Lock()
	client.shutdown = true
	closing := client.closing
	if err == io.EOF {
		if closing {
			err = ErrShutdown
		} else {
			err = io.ErrUnexpectedEOF
		}
	}
	for _, call := range client.pending {
		call.Error = err
		call.done()
	}
	client.mutex.Unlock()

	log.LogMessage("quit read loop")

}
Ejemplo n.º 2
0
//增加一行,row=-1时,在表格最后面插入一行,否则在row处插入,返回-1插入失败,否则返回插入的行号
func (rec *GlobalDataTestRec) AddByBytes(row int, rowdata []byte) int {
	if rec.owner.InBase && rec.owner.InScene { //当玩家在场景中时,在base中修改scenedata,在同步时会被覆盖.
		log.LogError("the TaskAccepted will be overwritten by scenedata")
	}

	lr := util.NewLoadArchiver(rowdata)

	var id string
	var flag int8

	if err := lr.Read(&id); err != nil {
		return -1
	}
	if err := lr.Read(&flag); err != nil {
		return -1
	}

	return rec.AddRowValue(row, id, flag)
}
Ejemplo n.º 3
0
//获取rpc消息的错误代码,返回0没有错误
func GetReplyError(msg *rpc.Message) int32 {
	ar := util.NewLoadArchiver(msg.Header)
	if len(msg.Header) <= 8 {
		return 0
	}
	ar.Seek(8, 0)

	haserror, err := ar.ReadInt8()
	if err != nil {
		return 0
	}

	if haserror != 1 {
		return 0
	}

	errcode, err := ar.ReadInt32()
	if err != nil {
		return 0
	}

	return errcode
}
Ejemplo n.º 4
0
func NewHeadReader(msg *rpc.Message) *util.LoadArchive {
	return util.NewLoadArchiver(msg.Header)
}
Ejemplo n.º 5
0
func NewMessageReader(msg *rpc.Message) *util.LoadArchive {
	return util.NewLoadArchiver(msg.Body)
}