Go Home Page
The Go Programming Language

Package srpc

import "exp/nacl/srpc"

This package implements Native Client's simple RPC (SRPC).

Package files

client.go msg.go server.go

func Add

func Add(name, fmt string, handler Handler)

Add registers a handler for the named method. Fmt is a Native Client format string, a sequence of alphabetic characters representing the types of the parameter values, a colon, and then a sequence of alphabetic characters representing the types of the returned values. The format characters and corresponding dynamic types are:

b	bool
C	[]byte
d	float64
D	[]float64
h	int	// a file descriptor (aka handle)
i	int32
I	[]int32
s	string

func Enabled

func Enabled() bool

Enabled returns true if SRPC is enabled in the Native Client runtime.

func Serve

func Serve(fd int) os.Error

Serve accepts new SRPC connections from the file descriptor fd and answers RPCs issued on those connections. It closes fd and returns an error if the imc_accept system call fails.

func ServeRuntime

func ServeRuntime() os.Error

ServeRuntime serves RPCs issued by the Native Client embedded runtime. This should be called by main once all methods have been registered using Add.

type Client

A Client represents the client side of an SRPC connection.

type Client struct {
    // contains unexported fields
}

func NewClient

func NewClient(fd int) (c *Client, err os.Error)

NewClient allocates a new client using the file descriptor fd.

func (*Client) NewRPC

func (c *Client) NewRPC(done chan *RPC) *RPC

NewRPC creates a new RPC on the client connection.

type Errno

An Errno is an SRPC status code.

type Errno uint32

const (
    OK Errno = 256 + iota
    ErrBreak
    ErrMessageTruncated
    ErrNoMemory
    ErrProtocolMismatch
    ErrBadRPCNumber
    ErrBadArgType
    ErrTooFewArgs
    ErrTooManyArgs
    ErrInArgTypeMismatch
    ErrOutArgTypeMismatch
    ErrInternalError
    ErrAppError
)

func (Errno) String

func (e Errno) String() string

type Handler

A Handler is a handler for an SRPC method. It reads arguments from arg, checks size for array limits, writes return values to ret, and returns an Errno status code.

type Handler interface {
    Run(arg, ret []interface{}, size []int) Errno
}

type RPC

An RPC represents a single RPC issued by a client.

type RPC struct {
    Ret   []interface{} // Return values
    Done  chan *RPC     // Channel where notification of done arrives
    Errno Errno         // Status code
    // contains unexported fields
}

func (*RPC) Call

func (r *RPC) Call(name string, arg []interface{}) (ret []interface{}, err Errno)

Call is a convenient wrapper that starts the RPC request, waits for it to finish, and then returns the results. Its implementation is:

r.Start(name, arg);
<-r.Done;
return r.Ret, r.Errno;

func (*RPC) Start

func (r *RPC) Start(name string, arg []interface{})

Start issues an RPC request for method name with the given arguments. The RPC r must not be in use for another pending request. To wait for the RPC to finish, receive from r.Done and then inspect r.Ret and r.Errno.

Bugs

Add's format string should be replaced by analyzing the type of an arbitrary func passed in an interface{} using reflection.