rpc

package
v0.0.0-...-c54de71 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const MagicNumber = 0x3bef5c

Variables

View Source
var DefaultOption = &Option{
	MagicNumber:          MagicNumber,
	CodecType:            codec.GobType,
	ConnectionTimeoutSec: 10 * time.Second,
	HandleTimeoutSec:     0,
}
View Source
var DefaultServer = NewServer()

DefaultServer is the default instance of *Server.

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

Functions

func Accept

func Accept(lis net.Listener)

Accept accepts connections on the listener and serves requests for each incoming connection.

func HandleHTTP

func HandleHTTP()

HandleHTTP registers an HTTP handler for RPC messages on rpcPath, and a debugging handler on debugPath

func Register

func Register(rcvr interface{}) error

Register publishes the receiver's methods in the DefaultServer.

Types

type Args

type Args struct{ Num1, Num2 int }

type Call

type Call struct {
	Seq           uint64      // sequence number chosen by client
	ServiceMethod string      // format "Service.Method"
	Args          interface{} // arguments to the function
	Reply         interface{} // reply from the function
	Error         error       // if error occurs, it will be set
	Done          chan *Call  // strobes when call is complete
}

Call represents an active RPC.

type Client

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

Client represents an RPC Client. There may be multiple outstanding Calls associated with a single Client, and a Client may be used by multiple goroutines simultaneously.

func Dial

func Dial(network, address string, opts ...*Option) (client *Client, err error)

Dial connects to an RPC server at the specified network address.

func DialHttp

func DialHttp(network, address string, opts ...*Option) (client *Client, err error)

func NewClient

func NewClient(conn net.Conn, opt *Option) (*Client, error)

NewClient returns a new Client.

func NewHTTPClient

func NewHTTPClient(conn net.Conn, opt *Option) (*Client, error)

func XDial

func XDial(rpcAddr string, opts ...*Option) (*Client, error)

func (*Client) Call

func (client *Client) Call(ctx context.Context, serviceMethod string, args, reply interface{}) error

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

func (*Client) Close

func (client *Client) Close() error

func (*Client) Go

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

Go invokes the function asynchronously. It returns the Call structure representing the invocation.

func (*Client) IsAvailable

func (client *Client) IsAvailable() bool

IsAvailable returns true if the client does work; in other words, it's not shutdown and not closing.

type Foo

type Foo int

func (Foo) Sleep

func (f Foo) Sleep(args Args, reply *int) error

func (Foo) Sum

func (f Foo) Sum(args Args, reply *int) error

Sum exported method

type Option

type Option struct {
	MagicNumber          int           // MagicNumber marks this's a ggtrpc request
	CodecType            codec.Type    // client may choose different Codec to encode body
	ConnectionTimeoutSec time.Duration // 0 means no limit
	HandleTimeoutSec     time.Duration // 0 means no limit
}

type Server

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

Server represents an RPC Server.

func NewServer

func NewServer() *Server

NewServer returns a new Server.

func (*Server) Accept

func (server *Server) Accept(lis net.Listener)

Accept accepts connections on the listener and serves requests for each incoming connection.

func (*Server) HandleHTTP

func (server *Server) HandleHTTP()

func (*Server) Register

func (server *Server) Register(rcvr interface{}) error

Register publishes in the server the set of methods of the receiver value that satisfy the following conditions: - exported method of exported type - two arguments, both of exported type or builtin type - the second argument is a pointer - one return value, of type error

func (*Server) ServeHTTP

func (server *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) ServerConn

func (server *Server) ServerConn(conn io.ReadWriteCloser)

ServerConn runs the server on a single connection. ServerConn blocks, serving the connection until the client hangs up.

Jump to

Keyboard shortcuts

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