brpc

package
v0.0.0-...-074040a Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MagicNumber = 0x123abc
)

Variables

View Source
var DefaultOption = &Option{
	MagicNumber:    MagicNumber,
	CodecType:      codec.TypeGob,
	ConnectTimeout: time.Second * 10,
}
View Source
var DefaultServer = NewServer()
View Source
var ErrShutdown = errors.New("connection is shut down")

Functions

func Accept

func Accept(listener net.Listener)

func Register

func Register(regObj any) error

Register publishes the receiver's methods in the DefaultServer.

Types

type Call

type Call struct {
	Seq           uint64
	ServiceMethod string      // format "<service>.<method>"
	Args          interface{} // arguments to the function
	Resp          interface{} // resp 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, error)

Dial connects to an RPC server at the specified network address

func NewClient

func NewClient(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 any) error

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

func (*Client) Close

func (client *Client) Close() error

Close the connection

func (*Client) Go

func (client *Client) Go(serviceMethod string, args, resp any, 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 return true if the client does work

type Option

type Option struct {
	MagicNumber int
	CodecType   codec.Type

	ConnectTimeout time.Duration // 0 means no limit
	HandleTimeout  time.Duration
}

Option this filed is the start in conn msg [<- Option ->][<- Header ->][<- Body ->][<- Header ->][<- Body ->]...... part of [<- Option ->] is codec by json part of [<- Header ->] and [<- Body ->] is codec by Option.CodecType

type Server

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

Server represents an RPC Server.

func NewServer

func NewServer() *Server

func (*Server) Accept

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

Accept accepts connections on the listener and serves requests

func (*Server) Register

func (server *Server) Register(regObj any) error

Register publishes in the server the set of methods of the

func (*Server) ServeConn

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

ServeConn handle the incoming conn

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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