Documentation
¶
Index ¶
- Constants
- Variables
- type Client
- type Code
- type ConnURL
- type Dialer
- func (d *Dialer) Dial(u *ConnURL) (Client, error)
- func (d *Dialer) DialContext(ctx context.Context, u *ConnURL) (Client, error)
- func (d *Dialer) DialUpgrade(ctx context.Context, u *url.URL, proto string) (conn net.Conn, err error)
- func (d *Dialer) RoundTrip(req *http.Request) (conn net.Conn, resp *http.Response, err error)
- type PoolMux
- func (p *PoolMux) Acquire() (cli Client, unique bool, err error)
- func (p *PoolMux) Busy() int
- func (p *PoolMux) Call(method string, args, reply any) error
- func (p *PoolMux) Close() error
- func (p *PoolMux) Code() Code
- func (p *PoolMux) MaxConns() int
- func (p *PoolMux) Preconnect(n int) error
- func (p *PoolMux) Release(cli Client, unique bool)
- type PoolMuxConfig
- type Server
- type ServerFunc
- type ServerProtocol
- type Stream
- type UpgradeListener
- type UpgradeServer
- type YamuxCode
Constants ¶
const ( FlagReply jrpcSeq = 1 << 31 FlagMask jrpcSeq = (1 << 31) - 1 )
const DefaultURL = "pmtp://127.0.0.1"
Variables ¶
var RpcCodeList = []Code{ YamuxCode{CodeJRPC}, CodeJRPC, YamuxCode{CodeJSON}, CodeJSON, }
var RpcUpgradeServer = MakeUpgradeServer(RpcCodeList...)
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
Busy() int // number of pending requests, -1 if closed
Call(method string, args any, reply any) error
Close() error
Code() Code
}
type Code ¶
type Code interface {
Open(conn net.Conn) (Client, error)
Serve(conn net.Conn, sv Server)
String() string
}
var CodeJRPC Code = jrpcCode{}
var CodeJSON Code = &stdCodeAdapter{jsonCode{}, "json-rpc"}
func FindCodeByName ¶
type ConnURL ¶
type ConnURL struct {
Path string
RawQuery string
Host string
Secret string
DisablePoolMux bool
DisableYamux bool
Code Code
Websocket bool
TLS bool
}
URL parsing.
type Dialer ¶
type Dialer struct {
NetDialContext func(ctx context.Context, network string, address string) (net.Conn, error)
TLSClientConfig *tls.Config
}
Dialer is a dialer for RPC connections over HTTP and WebSocket.
func (*Dialer) DialContext ¶
func (*Dialer) DialUpgrade ¶
type PoolMux ¶
type PoolMux struct {
Connect func(c Code) (Client, error)
// contains filtered or unexported fields
}
PoolMux is a pool of pmtp.Clients, if a code is of type ymux, the pool will be initially populated with the underlying code and switch to a shared ymux connection when the pool is drained.
func NewPoolMux ¶
NewPoolMux creates a new pool of pmtp.Clients with a default size.
func NewPoolMuxConfig ¶
func NewPoolMuxConfig(cfg PoolMuxConfig) (*PoolMux, error)
NewPoolMuxConfig creates a new pool of pmtp.Clients with a given configuration.
func (*PoolMux) Acquire ¶
Acquire returns a pmtp.Client from the pool, if the pool is closed, it returns io.ErrClosedPipe. If the pool is drained, it will share another connection or return the muxed connection.
func (*PoolMux) Busy ¶
Implement the pmtp.Client interface. Busy returns the number of busy connections in the pool.
func (*PoolMux) Call ¶
Call is a wrapper around pmtp.Client.Call, it acquires a client from the pool,
func (*PoolMux) Preconnect ¶
Preconnect ensures that the pool is prepopulated with a given number of connections.
type PoolMuxConfig ¶
type PoolMuxConfig struct {
// Code is the code of the pool.
Code Code
// Connect is the function used to create a new connection.
Connect func(c Code) (Client, error)
// MaxConns is the maximum number of connections in the pool.
MaxConns int
// Preconnect is the number of connections to preconnect.
Preconnect int
// AfterClose is a function called after the pool is closed.
AfterClose func()
}
type ServerFunc ¶
type ServerFunc func(method string, body json.RawMessage) (any, error)
func (ServerFunc) ServeRPC ¶
func (f ServerFunc) ServeRPC(method string, body json.RawMessage) (any, error)
type ServerProtocol ¶
type UpgradeListener ¶
type UpgradeListener struct {
UpgradeServer[erasedProtocol, any]
// contains filtered or unexported fields
}
func NewUpgradeListener ¶
func NewUpgradeListener(name string) *UpgradeListener
func (*UpgradeListener) Addr ¶
func (u *UpgradeListener) Addr() net.Addr
func (*UpgradeListener) Close ¶
func (u *UpgradeListener) Close() error
func (*UpgradeListener) ServeHTTP ¶
func (u *UpgradeListener) ServeHTTP(w http.ResponseWriter, r *http.Request)
type UpgradeServer ¶
type UpgradeServer[Proto ServerProtocol[Arg], Arg any] struct { Websocket websocket.Upgrader Protocols map[string]Proto }
func MakeRPCServer ¶
func MakeRPCServer[Arg any](sv func(conn net.Conn, code Code, arg Arg)) UpgradeServer[*rpcServerAdapter[Arg], Arg]
func MakeUpgradeServer ¶
func MakeUpgradeServer[Proto ServerProtocol[Arg], Arg any](protos ...Proto) UpgradeServer[Proto, Arg]
func (*UpgradeServer[Proto, Arg]) Upgrade ¶
func (u *UpgradeServer[Proto, Arg]) Upgrade(w http.ResponseWriter, r *http.Request, arg Arg)