rpc

package
v0.0.0-...-fd5963e Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorRPCConnect = errors.New("RPC couldn't connect")

ErrorRPCConnect is returned if we can't connect to the RPC server.

Functions

func GenID

func GenID() string

GenID returns a unique string to be used as an RPC id for cancellation. This implementation works by using 120 random bits as a process identifier combined with 64 bits of sequence number. The values that it produces are printable (though things should work regardless).

func GetBuffer

func GetBuffer(n int) []byte

GetBuffer returns a []byte with length n and capacity >= n. The buffer may not be zeroed!

func PutBuffer

func PutBuffer(b []byte, exclusive bool)

PutBuffer returns a buffer to the pool. It's okay to call this on any buffer that isn't going to be used again, whether it came from GetBuffer or not. 'exclusive' indicates whether the caller is the exclusive owner of the buffer. (If exclusive is false, obviously, the buffer cannot be put in a pool. PutBuffer has this signature to be able to use it conveniently with BulkData.Get)

func RegisterName

func RegisterName(name string, rcvr interface{}) error

RegisterName wraps rpc.RegisterName, which uses the default RPC server.

func StartStandaloneRPCServer

func StartStandaloneRPCServer(addr string)

StartStandaloneRPCServer starts the default RPC server.

Types

type BulkData

type BulkData interface {
	Get() ([]byte, bool) // extract and return bulk data and exclusive flag
	Set([]byte, bool)    // put bulk data back and exclusive flag in the struct
}

BulkData is an interface that lets a struct expose a single field as bulk data. The data may be exclusively owned by the caller or not; the bool value is true if it is.

type CancelAction

type CancelAction struct {
	Method string
	Req    interface{}
}

CancelAction describes the cancel RPC to send if the primary RPC is cancelled on the client side.

type ConnectionCache

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

ConnectionCache creates and caches RPC connections to addresses.

ConnectionCache is thread-safe.

func NewConnectionCache

func NewConnectionCache(dialTimeout, rpcTimeout time.Duration, maxConns int) *ConnectionCache

NewConnectionCache makes a new ConnectionCache. dialTimeout is the timeout used for connecting. maxConns is the size of the cache. If we have more than that many connections, we may drop idle connections. If maxConns is zero, we never drop idle connections.

func (*ConnectionCache) CloseAll

func (cc *ConnectionCache) CloseAll() (err error)

CloseAll closes all connections in the cache. It returns any error that it got when closing connections, but even in the case of error, the cache will no longer hold references to the connections.

func (*ConnectionCache) Remove

func (cc *ConnectionCache) Remove(addr string)

Remove removes and closes a connection from the cache if a connection to "addr" exists.

func (*ConnectionCache) Send

func (cc *ConnectionCache) Send(ctx context.Context, addr, method string, req, reply interface{}) error

Send wraps up the basic pattern of calling an RPC with a timeout.

func (*ConnectionCache) SendWithCancel

func (cc *ConnectionCache) SendWithCancel(ctx context.Context, addr, method string, req, reply interface{}, can *CancelAction) error

SendWithCancel is like Send, but allows specifying an action to be taken if the RPC is cancelled on the client side. Currently the action must be another RPC, which will be done asynchronously, and its return value or error will be ignored.

Jump to

Keyboard shortcuts

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