func (c *clientCodec) ReadResponseHeader(r *rpc.Response) os.Error {
	c.resp.reset()
	if err := c.dec.Decode(&c.resp); err != nil {
		return err
	}

	c.mutex.Lock()
	r.ServiceMethod = c.pending[c.resp.Id]
	c.pending[c.resp.Id] = "", false
	c.mutex.Unlock()

	r.Error = ""
	r.Seq = c.resp.Id
	if c.resp.Error != nil {
		x, ok := c.resp.Error.(string)
		if !ok {
			return fmt.Errorf("invalid error %v", c.resp.Error)
		}
		if x == "" {
			x = "unspecified error"
		}
		r.Error = x
	}
	return nil
}
示例#2
0
文件: client.go 项目: eclark/protorpc
func (c *clientCodec) ReadResponseHeader(r *rpc.Response) (err os.Error) {
	c.resp.header.Reset()

	lbuf := make([]byte, lenSize)
	_, err = io.ReadFull(c.c, lbuf)
	if err != nil {
		return
	}

	pbuf := make([]byte, decodeLen(lbuf))
	_, err = io.ReadFull(c.c, pbuf)
	if err != nil {
		return
	}

	c.resp.header.SetBuf(pbuf)

	h := new(Header)
	err = c.resp.header.Unmarshal(h)
	if err != nil {
		return
	}

	r.Seq = *h.Seq
	r.ServiceMethod = *h.ServiceMethod
	r.Error = *h.Error

	return nil
}
示例#3
0
func (c *clientCodec) ReadResponseHeader(r *rpc.Response) os.Error {
	c.resp.reset()
	if err := c.dec.Decode(&c.resp); err != nil {
		return err
	}

	c.mutex.Lock()
	r.ServiceMethod = c.pending[c.resp.Id]
	c.pending[c.resp.Id] = "", false
	c.mutex.Unlock()

	r.Seq = c.resp.Id
	r.Error = c.resp.Error
	return nil
}