protocol

package
v0.0.0-...-76993e2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	REQUEST  = 1
	RESPONSE = 2
)

Variables

View Source
var ErrShutdown = errors.New("connection is shut down")

Functions

This section is empty.

Types

type Call

type Call struct {
	ServiceMethod string      // The name of the service and method to call.
	Args          interface{} // The argument to the function (*struct).
	Reply         interface{} // The reply from the function (*struct).
	Error         error       // After completion, the error status.
	Done          chan *Call  // Strobes when call is complete.
}

Call represents an active RPC.

type Codec

type Codec interface {
	ReadHeader(*RepReq) error
	ReadBody(interface{}) error
	Write(*RepReq, interface{}) error

	Close() error
}

A Codec implements reading of RPC requests and writing of RPC responses for the server side of an RPC session. The server calls ReadHeader and ReadBody in pairs to read requests from the connection, and it calls Write to write a response back. The server calls Close when finished with the connection. ReadBody may be called with a nil argument to force the body of the request to be read and discarded.

type ExtendedMethod

type ExtendedMethod interface {
	SetProtocol(*Protocol)
}

type Protocol

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

Protocol represents an RPC Protocol.

func NewClientWithCodec

func NewClientWithCodec(codec Codec) *Protocol

NewClientWithCodec uses the specified codec to encode requests and decode responses.

func NewProtocol

func NewProtocol(codec Codec) *Protocol

NewServer returns a new Server.

func (*Protocol) Call

func (s *Protocol) Call(serviceMethod string, args interface{}, reply interface{}) error

Call invokes the named function, waits for it to complete, and returns its error status.

func (*Protocol) Close

func (s *Protocol) Close() error

func (*Protocol) Go

func (s *Protocol) Go(serviceMethod string, args interface{}, reply interface{}, done chan *Call) *Call

Go invokes the function asynchronously. It returns the Call structure representing the invocation. The done channel will signal when the call is complete by returning the same Call object. If done is nil, Go will allocate a new channel. If non-nil, done must be buffered or Go will deliberately crash.

func (*Protocol) Register

func (p *Protocol) Register(rcvr interface{}) error

Register publishes in the server the set of methods of the receiver value that satisfy the following conditions:

  • exported method
  • two arguments, both pointers to exported structs
  • one return value, of type error

It returns an error if the receiver is not an exported type or has no methods or unsuitable methods. It also logs the error using package log. The client accesses each method using a string of the form "Type.Method", where Type is the receiver's concrete type.

func (*Protocol) RegisterName

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

RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.

func (*Protocol) Serve

func (p *Protocol) Serve()

type RepReq

type RepReq struct {
	Type          int `bson:",minsize"` // Either REQUEST OR RESPONSE
	ServiceMethod string
	Seq           uint64
	Error         string `bson:",omitempty"`
	// contains filtered or unexported fields
}

type ServerError

type ServerError string

ServerError represents an error that has been returned from the remote side of the RPC connection.

func (ServerError) Error

func (e ServerError) Error() string

Jump to

Keyboard shortcuts

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