rpc

package
v0.167.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 9 Imported by: 4 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rpc implements rpc engine.

Index

Constants

This section is empty.

Variables

View Source
var ErrEngineClosed = errors.New("engine was closed")

ErrEngineClosed means that engine was closed.

Functions

func NopDrop

func NopDrop(Request) error

NopDrop does nothing.

func NopSend

NopSend does nothing.

Types

type DropHandler

type DropHandler func(req Request) error

DropHandler handles drop rpc requests.

type Engine

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

Engine handles RPC requests.

func New

func New(send Send, cfg Options) *Engine

New creates new rpc Engine.

func (*Engine) Close

func (e *Engine) Close()

Close gracefully closes the engine. All pending requests will be awaited. All Do method calls of closed engine will return ErrEngineClosed error.

func (*Engine) Do

func (e *Engine) Do(ctx context.Context, req Request) error

Do sends request to server and blocks until response is received, performing multiple retries if needed.

func (*Engine) ForceClose

func (e *Engine) ForceClose()

ForceClose forcibly closes the engine. All pending requests will be canceled. All Do method calls of closed engine will return ErrEngineClosed error.

func (*Engine) NotifyAcks

func (e *Engine) NotifyAcks(ids []int64)

NotifyAcks notifies engine about received acknowledgements.

func (*Engine) NotifyError

func (e *Engine) NotifyError(msgID int64, rpcErr error)

NotifyError notifies engine about received RPC error.

func (*Engine) NotifyErrorAll

func (e *Engine) NotifyErrorAll(rpcErr error)

NotifyErrorAll notifies every pending request about rpcErr, e.g. when the session they were sent in is gone and they must be sent again in a new one.

func (*Engine) NotifyErrorBefore

func (e *Engine) NotifyErrorBefore(msgID int64, rpcErr error)

NotifyErrorBefore notifies pending requests with msg_id less than msgID about rpcErr, e.g. requests sent in a server session that was replaced (new_session_created with first_msg_id).

func (*Engine) NotifyResult

func (e *Engine) NotifyResult(msgID int64, b *bin.Buffer) error

NotifyResult notifies engine about received RPC response.

func (*Engine) TryNotifyError

func (e *Engine) TryNotifyError(msgID int64, rpcErr error) bool

TryNotifyError is NotifyError for a message that may be no request, e.g. a ping rejected by bad_server_salt: it reports whether a request waited for msgID, and logs nothing if none did.

type Options

type Options struct {
	RetryInterval time.Duration
	MaxRetries    int
	Logger        log.Logger
	Clock         clock.Clock
	DropHandler   DropHandler
	// Backlog returns how long the data already written to the connection
	// may take to reach the server. A request is not acknowledged before
	// its own data arrives, so a resend is postponed by it. Nil is zero.
	Backlog func() time.Duration
}

Options of rpc engine.

type Request

type Request struct {
	MsgID  int64
	SeqNo  int32
	Input  bin.Encoder
	Output bin.Decoder
}

Request represents client RPC request.

type RetryLimitReachedErr

type RetryLimitReachedErr struct {
	Retries int
}

RetryLimitReachedErr means that server does not acknowledge request after multiple retries.

Engine.Do no longer returns it: after the last resend it keeps waiting for the result until the context is done or the engine is closed. The type is kept for compatibility.

func (*RetryLimitReachedErr) Error

func (r *RetryLimitReachedErr) Error() string

func (*RetryLimitReachedErr) Is

func (r *RetryLimitReachedErr) Is(err error) bool

Is reports whether err is RetryLimitReachedErr.

type Send

type Send func(ctx context.Context, msgID int64, seqNo int32, in bin.Encoder) error

Send is a function that sends requests to the server.

Jump to

Keyboard shortcuts

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