Beispiel #1
0
func AppendArgs(msg *rpc.Message, args ...interface{}) {
	w := &BodyWriter{util.NewStoreArchiver(msg.Body), msg}
	if len(args) > 0 {
		for i := 0; i < len(args); i++ {
			err := w.Write(args[i])
			if err != nil {
				msg.Free()
				panic("write args failed")
			}
		}
		w.Flush()
	}
}
Beispiel #2
0
//向客户端发包,存进一个消息队列,异步发送
func (c *ClientNode) SendMessage(message *rpc.Message) error {
	if c.quit {
		return fmt.Errorf("client is quit")
	}
	message.Dup()
	select {
	case c.Sendbuf <- message:
		return nil
	default:
		message.Free()
		return fmt.Errorf("send buffer full")
	}
}
Beispiel #3
0
func NewHeadWriter(msg *rpc.Message) *HeadWriter {
	msg.Header = msg.Header[:0]
	w := &HeadWriter{util.NewStoreArchiver(msg.Header), msg}
	return w
}
Beispiel #4
0
func NewMessageWriter(msg *rpc.Message) *BodyWriter {
	msg.Body = msg.Body[:0]
	w := &BodyWriter{util.NewStoreArchiver(msg.Body), msg}
	return w
}