sock

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRetryAttempts          = uint8(5)
	DefaultRetryInterval          = time.Second
	DefaultExitWaitTimeout        = time.Second * 30
	DefaultMaxBufferSize          = 10000
	DefaultTcpKeepAliveCnt        = -1
	DefaultTcpKeepAliveIdleSec    = -1
	DefaultHeartbeatTTLSec        = 30 // unit: millisecond
	DefaultHeartbeatTimeoutSec    = 5  // unit: millisecond
	DefaultHeartbeatIvlSec        = 15 // unit: millisecond
	DefaultReconnectIvlMillSec    = 100
	DefaultReconnectIvlMaxMillSec = 0
	DefaultSndhwm                 = 10000
	DefaultSendTimeoutSec         = 0
	DefaultRecvTimeoutSec         = 0
)

Variables

Functions

This section is empty.

Types

type Option

type Option func(s *Sock)

func DisableRestart

func DisableRestart() Option

func EnableTcpKeepAlive

func EnableTcpKeepAlive() Option

func WithAttach

func WithAttach() Option

func WithCtx

func WithCtx(val context.Context) Option

func WithEndpoint

func WithEndpoint(val string) Option

func WithExitWaitTimeout

func WithExitWaitTimeout(val time.Duration) Option

func WithHeartbeatIvlSec

func WithHeartbeatIvlSec(val int) Option

func WithHeartbeatTTLSec

func WithHeartbeatTTLSec(val int) Option

func WithHeartbeatTimoutSec

func WithHeartbeatTimoutSec(val int) Option

func WithInChannel added in v1.0.1

func WithInChannel(val chan []byte) Option

func WithMaxBufferSize

func WithMaxBufferSize(val int) Option

func WithOutChannel added in v1.0.1

func WithOutChannel(val chan []byte) Option

func WithRecvTimeoutSec added in v1.0.1

func WithRecvTimeoutSec(val int) Option

func WithRetryAttempts

func WithRetryAttempts(val int) Option

func WithRetryInterval

func WithRetryInterval(val time.Duration) Option

func WithSendTimeoutSec added in v1.0.1

func WithSendTimeoutSec(val int) Option

func WithSndhwm

func WithSndhwm(val int) Option

func WithTcpKeepAliveCnt

func WithTcpKeepAliveCnt(val int) Option

func WithTcpKeepAliveIdleSec

func WithTcpKeepAliveIdleSec(val int) Option

func WithType

func WithType(val string) Option

type RetryMsg

type RetryMsg struct {
	Msg      []byte
	MaxRetry uint8
	// contains filtered or unexported fields
}

func NewRetryMsg

func NewRetryMsg(msg []byte, retry uint8) *RetryMsg

func (*RetryMsg) GetRetryTimes added in v1.0.1

func (r *RetryMsg) GetRetryTimes() uint8

GetRetryTimes gets msg current retry times

func (*RetryMsg) IterRetryTimes

func (r *RetryMsg) IterRetryTimes()

IterRetryTimes used to iter the retry times

func (*RetryMsg) Retry

func (r *RetryMsg) Retry() bool

Retry get the retry state. if the retry time reach the max retry times, Retry will return false.

type Sock

type Sock struct {
	ID string

	MaxBufferSize int

	// socket connection args
	Type     int
	Endpoint string

	Sndhwm int

	// reconnect args
	DisableRestart         atom.AtomicBool
	ReconnectIvlMillSec    int
	ReconnectIvlMaxMillSec int

	// heartbeat args
	HeartbeatIvlSec    uint16
	HeartbeatTimoutSec uint16
	HeartbeatTTLSec    uint16

	// tcp args
	EnableTcpKeepAlive  bool
	TcpKeepAliveIdleSec int16
	TcpKeepAliveCnt     int8

	RetryInterval time.Duration
	RetryAttempts uint8

	// safe destroy args
	ExitWaitTimeout time.Duration

	SendTimeoutSec uint16
	RecvTimeoutSec uint16
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Sock

func (*Sock) Attach

func (s *Sock) Attach() (*goczmq.Sock, error)

Attach attaches a socket to zero or more endpoints.

call bind when attach is equal to false
call connect when attach is equal to true

func (*Sock) Consumer

func (s *Sock) Consumer()

Consumer receive msg from sock and charge into 'out' channel. optional socket type: SUB/PULL

func (*Sock) EmptyBuffer

func (s *Sock) EmptyBuffer() bool

func (*Sock) GetDropMsgCount added in v1.0.2

func (s *Sock) GetDropMsgCount() uint64

GetDropMsgCount gets the total count of msg sock has dropped ever

func (*Sock) GetID added in v1.0.2

func (s *Sock) GetID() string

GetID gets the uniq it of socket

func (*Sock) GetInChannel

func (s *Sock) GetInChannel() chan []byte

GetInChannel returns in channel

func (*Sock) GetInCount

func (s *Sock) GetInCount() int

GetInCount gets msg count int channel 'in'

func (*Sock) GetOutChannel

func (s *Sock) GetOutChannel() chan []byte

GetOutChannel returns out channel

func (*Sock) GetOutCount

func (s *Sock) GetOutCount() int

GetOutCount gets msg count int channel 'out'

func (*Sock) GetRecvMsgCount added in v1.0.2

func (s *Sock) GetRecvMsgCount() uint64

GetRecvMsgCount gets the total count of msg sock has received

func (*Sock) GetRetryCount

func (s *Sock) GetRetryCount() int

GetRetryCount gets msg count int channel 'retryCh'

func (*Sock) GetSendMsgCount added in v1.0.2

func (s *Sock) GetSendMsgCount() uint64

GetSendMsgCount gets the total count of msg sock has published

func (*Sock) IsAutoRestart

func (s *Sock) IsAutoRestart() bool

IsAutoRestart gets the value of DisableRestart

func (*Sock) Publisher

func (s *Sock) Publisher()

Publisher sends msg in 'in' channel. optional sock type: PUB/PUSH

func (*Sock) Release

func (s *Sock) Release() error

Release tries release socket after all buffers be triggered

func (*Sock) Requester added in v1.0.1

func (s *Sock) Requester()

Requester send request msg in 'in' channel and save reply msg in 'out' channel

func (*Sock) Responser added in v1.0.1

func (s *Sock) Responser()

Responser recharge request msg into 'out' channel and get its response msg from 'in' channel

func (*Sock) StopAutoRestart

func (s *Sock) StopAutoRestart()

StopAutoRestart sets DisableRestart to true

Jump to

Keyboard shortcuts

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