func (p *pipeTransport) SendMessage(ctx context.Context, msg rpccapnp.Message) error { if !p.startSend() { return errClosed } defer p.finishSend() buf, err := msg.Segment().Message().Marshal() if err != nil { return err } mm, err := capnp.Unmarshal(buf) if err != nil { return err } msg, err = rpccapnp.ReadRootMessage(mm) if err != nil { return err } select { case p.w <- msg: return nil case <-ctx.Done(): return ctx.Err() case <-p.finish: return errClosed case <-p.otherFin: return errBrokenPipe } }
// copyRPCMessage clones an RPC packet. func copyRPCMessage(m rpccapnp.Message) rpccapnp.Message { mm := copyMessage(m.Segment().Message()) rpcMsg, err := rpccapnp.ReadRootMessage(mm) if err != nil { panic(err) } return rpcMsg }
func (s *streamTransport) SendMessage(ctx context.Context, msg rpccapnp.Message) error { s.wbuf.Reset() if err := s.enc.Encode(msg.Segment().Message()); err != nil { return err } if s.deadline != nil { // TODO(light): log errors if d, ok := ctx.Deadline(); ok { s.deadline.SetWriteDeadline(d) } else { s.deadline.SetWriteDeadline(time.Time{}) } } _, err := s.rwc.Write(s.wbuf.Bytes()) return err }