client

package
v0.0.0-...-6d6ed6a Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: MIT Imports: 9 Imported by: 3

Documentation

Index

Constants

View Source
const (
	KeepaliveTime  = 3 * time.Second
	KeepaliveIntvl = time.Second
)

Variables

View Source
var ErrServerInfoMismatch = errors.New("server info mismatch")

ErrServerInfoMismatch happens when ServerInfo of the client and server does not match.

Functions

func Apply

func Apply(ops []SetOption, o *Options)

func ApplyKeepAlive

func ApplyKeepAlive(ops []SetKeepaliveOption, o *KeepaliveOptions)

Types

type Delegate

type Delegate[T any] struct {
	// contains filtered or unexported fields
}

Delegate implements the core.ClientDelegate interface.

func New

func New[T any](info delegate.ServerInfo, transport Transport[T],
	ops ...SetOption) (d Delegate[T], err error)

New creates a new Delegate.

The Delegate expects to receive ServerInfo from the server upon creation.

Returns ErrServerInfoMismatch if the received ServerInfo does not match the specified one.

func NewWithoutInfo

func NewWithoutInfo[T any](transport Transport[T]) (d Delegate[T])

NewWithoutInfo for tests only.

func (Delegate[T]) Close

func (d Delegate[T]) Close() error

func (Delegate[T]) Flush

func (d Delegate[T]) Flush() error

func (Delegate[T]) LocalAddr

func (d Delegate[T]) LocalAddr() net.Addr

func (Delegate[T]) Options

func (d Delegate[T]) Options() Options

func (Delegate[T]) Receive

func (d Delegate[T]) Receive() (seq core.Seq, result core.Result, n int,
	err error)

func (Delegate[T]) RemoteAddr

func (d Delegate[T]) RemoteAddr() net.Addr

func (Delegate[T]) Send

func (d Delegate[T]) Send(seq core.Seq, cmd core.Cmd[T]) (n int, err error)

func (Delegate[T]) SetReceiveDeadline

func (d Delegate[T]) SetReceiveDeadline(deadline time.Time) error

func (Delegate[T]) SetSendDeadline

func (d Delegate[T]) SetSendDeadline(deadline time.Time) error

type KeepaliveDelegate

type KeepaliveDelegate[T any] struct {
	ccln.Delegate[T]
	// contains filtered or unexported fields
}

KeepaliveDelegate implements the core.ClientDelegate interface.

When there are no Commands to send, it initiates a Ping-Pong exchange with the server. It sends a Ping Command and expects a Pong Result, both represented as a single zero byte (like a ball being passed).

func NewKeepalive

func NewKeepalive[T any](d ccln.Delegate[T], ops ...SetKeepaliveOption) (
	kd KeepaliveDelegate[T])

NewKeepalive creates a new KeepaliveDelegate.

func (KeepaliveDelegate[T]) Close

func (d KeepaliveDelegate[T]) Close() (err error)

func (KeepaliveDelegate[T]) Flush

func (d KeepaliveDelegate[T]) Flush() (err error)

func (KeepaliveDelegate[T]) Keepalive

func (d KeepaliveDelegate[T]) Keepalive(muSn *sync.Mutex)

func (KeepaliveDelegate[T]) Receive

func (d KeepaliveDelegate[T]) Receive() (seq core.Seq, result core.Result,
	n int, err error)

type KeepaliveOptions

type KeepaliveOptions struct {
	KeepaliveTime  time.Duration
	KeepaliveIntvl time.Duration
}

type Options

type Options struct {
	ServerInfoReceiveDuration time.Duration
}

type ReconnectDelegate

type ReconnectDelegate[T any] struct {
	// contains filtered or unexported fields
}

ReconnectDelegate implements the core.ClientReconnectDelegate interface.

func NewReconnect

func NewReconnect[T any](info delegate.ServerInfo, factory TransportFactory[T],
	ops ...SetOption) (d ReconnectDelegate[T], err error)

NewReconnect creates a new ReconnectDelegate.

func NewReconnectWithoutInfo

func NewReconnectWithoutInfo[T any](factory TransportFactory[T],
	closedFlag *uint32,
	transport *atomic.Value,
	options Options,
) ReconnectDelegate[T]

NewReconnectWithoutInfo for tests only.

func (ReconnectDelegate[T]) Close

func (d ReconnectDelegate[T]) Close() (err error)

func (ReconnectDelegate[T]) Flush

func (d ReconnectDelegate[T]) Flush() error

func (ReconnectDelegate[T]) LocalAddr

func (d ReconnectDelegate[T]) LocalAddr() net.Addr

func (ReconnectDelegate[T]) Options

func (d ReconnectDelegate[T]) Options() Options

func (ReconnectDelegate[T]) Receive

func (d ReconnectDelegate[T]) Receive() (seq core.Seq, result core.Result,
	n int, err error)

func (ReconnectDelegate[T]) Reconnect

func (d ReconnectDelegate[T]) Reconnect() (err error)

func (ReconnectDelegate[T]) RemoteAddr

func (d ReconnectDelegate[T]) RemoteAddr() net.Addr

func (ReconnectDelegate[T]) Send

func (d ReconnectDelegate[T]) Send(seq core.Seq, cmd core.Cmd[T]) (n int,
	err error)

func (ReconnectDelegate[T]) SetReceiveDeadline

func (d ReconnectDelegate[T]) SetReceiveDeadline(deadline time.Time) error

func (ReconnectDelegate[T]) SetSendDeadline

func (d ReconnectDelegate[T]) SetSendDeadline(deadline time.Time) error

func (ReconnectDelegate[T]) Transport

func (d ReconnectDelegate[T]) Transport() Transport[T]

type SetKeepaliveOption

type SetKeepaliveOption func(o *KeepaliveOptions)

func WithKeepaliveIntvl

func WithKeepaliveIntvl(d time.Duration) SetKeepaliveOption

WithKeepaliveIntvl sets the interval between consecutive Ping Commands sent by the client.

func WithKeepaliveTime

func WithKeepaliveTime(d time.Duration) SetKeepaliveOption

WithKeepaliveTime sets the inactivity period after which the client starts sending Ping Commands to the server if no Commands have been sent.

type SetOption

type SetOption func(o *Options)

func WithServerInfoReceiveDuration

func WithServerInfoReceiveDuration(d time.Duration) SetOption

WithServerInfoReceiveDuration sets the duration the client will wait for the ServerInfo. If set to 0, the client waits indefinitely.

type Transport

type Transport[T any] interface {
	delegate.Transport[core.Cmd[T], core.Result]
	ReceiveServerInfo() (info delegate.ServerInfo, err error)
}

Transport is a transport for the client delegate.

It is used by the delegate to send Commands and receive Results.

type TransportFactory

type TransportFactory[T any] interface {
	New() (Transport[T], error)
}

TransportFactory is a factory which creates a ClientTransport.

Jump to

Keyboard shortcuts

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