srpc

package
v0.0.0-...-90c9d3a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2010 License: BSD-3-Clause, GooglePatentClause Imports: 8 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client represents the client side of an SRPC connection.

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

type Errno uint32

An Errno is an SRPC status code.

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

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

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 RPC

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

An RPC represents a single RPC issued by a client.

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.

Notes

Bugs

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL