tree: e408e467d06b965757bcc38972ade9893b520e07 [path history] [tgz]
  1. generate/
  2. rpcapi/
  3. test/
  4. client.go
  6. rpc.go
  7. rpc_binary.go
  8. rpc_binary_test.go
  9. rpc_test.go
  10. server.go


import ""

Package rpc implements a remote procedure call system.

RPC uses the binary package for serialization and the multiplexer package to merge in-flight requests onto a single stream.


var ErrInvalidHeader = NewError("Invalid RPC header")

ErrInvalidHeader is returned when either client or server detects an incorrectly formed rpc header.

func Serve

func Serve(logger log.Logger, r io.Reader, w io.Writer, mtu int, handler Handler)

Server implements the receiving side of a client server rpc pair. It listens on the reader for calls, and dispatches them to the supplied handler. Any result returned from the handler is then sent back down the writer.

type Client

type Client struct {

Client implements the sending side of a client-server rpc pair.

func NewClient

func NewClient(r io.Reader, w io.Writer, mtu int) Client

NewClient creates a new rpc client object that sends messages down the writer, and waits for responses on the reader. The client supports multiple in-flight rpc calls. The chunk size used for multiplexing the calls for fairness is specified by mtu.

func (Client) Send

func (b Client) Send(call binary.Object) (interface{}, error)

Send encodes an rpc call and sends it to the server. It blocks until a reply is received or an error indicating there will be no reply occurs. This method is safe for concurrent use.

type Error

type Error struct {

Error is an implementation of error that can be sent over the wire.

func NewError

func NewError(msg string, args ...interface{}) *Error

NewError is used to create new rpc error objects with the specified human readable message.

func (*Error) Class

func (*Error) Class() binary.Class

func (*Error) Error

func (e *Error) Error() string

type Handler

type Handler func(interface{}) binary.Object

Handler is the signature for a function that handles incoming rpc calls.