示例#1
0
文件: prot_msgs.go 项目: allmad/madq
func (m *Msgs) PRead(r io.Reader) (err error) {
	var length uint16
	if err = binary.Read(r, binary.LittleEndian, &length); err != nil {
		return logex.Trace(err)
	}
	ret := make([]*message.Ins, length)
	i := 0
	for ; i < int(length); i++ {
		ret[i], err = message.Read(m.buf, r, message.RF_DEFAULT)
		if err != nil {
			err = logex.Trace(err)
			break
		}
	}
	m.underlay = ret[:i]
	return
}
示例#2
0
文件: topic.go 项目: allmad/madq
func (t *Ins) get(arg *getArgs, mustReply bool) error {
	if arg.size > MaxGetBenchSize {
		return ErrBenchSizeTooLarge.Trace(arg.size)
	}

	msgs := make([]*message.Ins, arg.size)
	var (
		msg *message.Ins
		err error
	)

	var header message.Header

	// check offset
	r := utils.NewBufio(&utils.Reader{t.file, arg.offset})
	p := 0
	for i := 0; i < arg.size; i++ {
		msg, err = message.Read(&header, r, message.RF_RESEEK_ON_FAULT)
		err = logex.Trace(err, i, arg.offset)
		if logex.EqualAny(err, ErrNeedAddToWaiter) {
			// not finish, add to waiterList
			t.addToWaiterList(newWaiter(arg, r.Offset(-1), p))
			break
		}
		if err != nil {
			break
		}
		msgs[p] = msg
		p++
	}

	if mustReply || p > 0 {
		arg.reply <- rpc.NewReply(t.Name, msgs[:p])
	}
	if logex.Equal(err, io.EOF) {
		err = nil
	}
	return err
}