Documentation ¶
Index ¶
- Variables
- func GenID() string
- func GetBuffer(n int) []byte
- func PutBuffer(b []byte, exclusive bool)
- func RegisterName(name string, rcvr interface{}) error
- func StartStandaloneRPCServer(addr string)
- type BulkData
- type CancelAction
- type ConnectionCache
- func (cc *ConnectionCache) CloseAll() (err error)
- func (cc *ConnectionCache) Remove(addr string)
- func (cc *ConnectionCache) Send(ctx context.Context, addr, method string, req, reply interface{}) error
- func (cc *ConnectionCache) SendWithCancel(ctx context.Context, addr, method string, req, reply interface{}, ...) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
GetBuffer returns a []byte with length n and capacity >= n. The buffer may not be zeroed!
func PutBuffer ¶
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 ¶
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.