本文整理匯總了Golang中zombiezen/com/go/capnproto2/std/capnp/rpc.Message.Return方法的典型用法代碼示例。如果您正苦於以下問題:Golang Message.Return方法的具體用法?Golang Message.Return怎麽用?Golang Message.Return使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類zombiezen/com/go/capnproto2/std/capnp/rpc.Message
的用法示例。
在下文中一共展示了Message.Return方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleReturnMessage
// handleReturnMessage is to handle a received return message.
// The caller is holding onto c.mu.
func (c *Conn) handleReturnMessage(m rpccapnp.Message) error {
ret, err := m.Return()
if err != nil {
return err
}
id := questionID(ret.AnswerId())
q := c.popQuestion(id)
if q == nil {
return fmt.Errorf("received return for unknown question id=%d", id)
}
if ret.ReleaseParamCaps() {
for _, id := range q.paramCaps {
c.releaseExport(id, 1)
}
}
q.mu.RLock()
qstate := q.state
q.mu.RUnlock()
if qstate == questionCanceled {
// We already sent the finish message.
return nil
}
releaseResultCaps := true
switch ret.Which() {
case rpccapnp.Return_Which_results:
releaseResultCaps = false
results, err := ret.Results()
if err != nil {
return err
}
if err := c.populateMessageCapTable(results); err == errUnimplemented {
um := newUnimplementedMessage(nil, m)
c.sendMessage(um)
return errUnimplemented
} else if err != nil {
c.abort(err)
return err
}
content, err := results.ContentPtr()
if err != nil {
return err
}
q.fulfill(content)
case rpccapnp.Return_Which_exception:
exc, err := ret.Exception()
if err != nil {
return err
}
e := error(Exception{exc})
if q.method != nil {
e = &capnp.MethodError{
Method: q.method,
Err: e,
}
} else {
e = bootstrapError{e}
}
q.reject(e)
case rpccapnp.Return_Which_canceled:
err := &questionError{
id: id,
method: q.method,
err: fmt.Errorf("receiver reported canceled"),
}
c.errorf("%v", err)
q.reject(err)
return nil
default:
um := newUnimplementedMessage(nil, m)
c.sendMessage(um)
return errUnimplemented
}
fin := newFinishMessage(nil, id, releaseResultCaps)
c.sendMessage(fin)
return nil
}