common

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 10, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultKeepaliveInteval is default keepalive interval duration.
	DefaultKeepaliveInteval = 20 * time.Second
	// DefaultKeepaliveMaxLifetime is default keepalive max lifetime.
	DefaultKeepaliveMaxLifetime = 90 * time.Second
)
View Source
const MaxUint24 = 16777215

MaxUint24 is the max value of Uint24.

Variables

View Source
var (
	ErrFrameLengthExceed  = errors.New("rsocket: frame length is greater than 24bits")
	ErrInvalidTransport   = errors.New("rsocket: invalid Transport")
	ErrInvalidFrame       = errors.New("rsocket: invalid frame")
	ErrInvalidContext     = errors.New("rsocket: invalid context")
	ErrInvalidFrameLength = errors.New("rsocket: invalid frame length")
	ErrReleasedResource   = errors.New("rsocket: resource has been released")
	ErrInvalidEmitter     = errors.New("rsocket: invalid emitter")
	ErrHandlerNil         = errors.New("rsocket: handler cannot be nil")
	ErrHandlerExist       = errors.New("rsocket: handler exists already")
	ErrSendFull           = errors.New("rsocket: frame send channel is full")
)

Error defines.

View Source
var (
	DefaultTCPWriteBuffSize = 16 * 1024
	DefaultTCPReadBuffSize  = 16 * 1024
	DefaultTCPSendChanSize  = 64
)

Some TCP connection settings.

Functions

func CalcTAU

func CalcTAU(halfLife float64, unit time.Duration) int64

CalcTAU returns tau.

func CountByteBuffer added in v0.0.4

func CountByteBuffer() int

CountByteBuffer returns amount of ByteBuff borrowed.

func NowInMicrosecond

func NowInMicrosecond() int64

NowInMicrosecond returns UNIX time in microsecond.

func RandAlphabetic added in v0.0.4

func RandAlphabetic(n int) (s string)

RandAlphabetic returns a string with random alphabets.

func RandAlphanumeric added in v0.0.4

func RandAlphanumeric(n int) (s string)

RandAlphanumeric returns a string with random alphabets and numbers.

func RandFloat64

func RandFloat64() (v float64)

RandFloat64 returns a random float64.

func RandIntn

func RandIntn(n int) (v int)

RandIntn returns a random int.

func ReturnByteBuffer

func ReturnByteBuffer(b *ByteBuff)

ReturnByteBuffer returns a ByteBuff.

func SetTCPBuffSize

func SetTCPBuffSize(r, w int) error

SetTCPBuffSize set TCP connection R/W buff size.

func SetTCPSendChanSize

func SetTCPSendChanSize(size int) error

SetTCPSendChanSize set TCP connection chan len.

Types

type ByteBuff

type ByteBuff bytebufferpool.ByteBuffer

ByteBuff provides byte buffer, which can be used for minimizing.

func BorrowByteBuffer

func BorrowByteBuffer() (bb *ByteBuff)

BorrowByteBuffer borrows a ByteBuff from pool.

func (*ByteBuff) Bytes

func (p *ByteBuff) Bytes() []byte

Bytes returns all bytes in ByteBuff.

func (*ByteBuff) Len

func (p *ByteBuff) Len() int

Len returns size of ByteBuff.

func (*ByteBuff) Reset

func (p *ByteBuff) Reset()

Reset clean all bytes.

func (*ByteBuff) Write

func (p *ByteBuff) Write(bs []byte) (n int, err error)

Writer write bytes to current ByteBuff.

func (*ByteBuff) WriteByte

func (p *ByteBuff) WriteByte(b byte) error

WriteByte write a byte to current ByteBuff.

func (*ByteBuff) WriteTo

func (p *ByteBuff) WriteTo(w io.Writer) (n int64, err error)

WriteTo write bytes to writer.

func (*ByteBuff) WriteUint24

func (p *ByteBuff) WriteUint24(n int) (err error)

WriteUint24 encode and write Uint24 to current ByteBuff.

type ErrorCode

type ErrorCode uint32

ErrorCode is code for RSocket error.

const (
	// ErrorCodeInvalidSetup means the setup frame is invalid for the server.
	ErrorCodeInvalidSetup ErrorCode = 0x00000001
	// ErrorCodeUnsupportedSetup means some (or all) of the parameters specified by the client are unsupported by the server.
	ErrorCodeUnsupportedSetup ErrorCode = 0x00000002
	// ErrorCodeRejectedSetup means server rejected the setup, it can specify the reason in the payload.
	ErrorCodeRejectedSetup ErrorCode = 0x00000003
	// ErrorCodeRejectedResume means server rejected the resume, it can specify the reason in the payload.
	ErrorCodeRejectedResume ErrorCode = 0x00000004
	// ErrorCodeConnectionError means the connection is being terminated.
	ErrorCodeConnectionError ErrorCode = 0x00000101
	// ErrorCodeConnectionClose means the connection is being terminated.
	ErrorCodeConnectionClose ErrorCode = 0x00000102
	// ErrorCodeApplicationError means application layer logic generating a Reactive Streams onError event.
	ErrorCodeApplicationError ErrorCode = 0x00000201
	// ErrorCodeRejected means Responder reject it.
	ErrorCodeRejected ErrorCode = 0x00000202
	// ErrorCodeCanceled means the Responder canceled the request but may have started processing it (similar to REJECTED but doesn't guarantee lack of side-effects).
	ErrorCodeCanceled ErrorCode = 0x00000203
	// ErrorCodeInvalid means the request is invalid.
	ErrorCodeInvalid ErrorCode = 0x00000204
)

func (ErrorCode) String

func (p ErrorCode) String() string

type Ewma

type Ewma interface {
	// Insert inserts a value.
	Insert(x float64)
	// Reset reset current value.
	Reset(x float64)
	// Value returns current value.
	Value() float64
}

Ewma is used to compute the exponential weighted moving average of a series of values

func NewEwma

func NewEwma(halfLife float64, unit time.Duration, initialValue float64) Ewma

NewEwma returns a new ewma.

type Quantile

type Quantile interface {
	// Estimation returns current estimation.
	Estimation() float64
	// Insert inserts new value.
	Insert(x float64)
}

Quantile is used by load balance.

func NewFrugalQuantile

func NewFrugalQuantile(quantile, increment float64) Quantile

NewFrugalQuantile returns a new quantile.

func NewMedianQuantile

func NewMedianQuantile() Quantile

NewMedianQuantile returns a new quantile.

type Uint24

type Uint24 [3]byte

Uint24 is 3 bytes unsigned integer.

func NewUint24

func NewUint24(n int) (v Uint24)

NewUint24 returns a new uint24.

func NewUint24Bytes

func NewUint24Bytes(bs []byte) Uint24

NewUint24Bytes returns a new uint24 from bytes.

func (Uint24) AsInt

func (p Uint24) AsInt() int

AsInt converts to int.

func (Uint24) Bytes

func (p Uint24) Bytes() []byte

Bytes returns bytes encoded.

func (Uint24) WriteTo

func (p Uint24) WriteTo(w io.Writer) (int64, error)

WriteTo encode and write bytes to a writer.

type Version

type Version [2]uint16

Version define the version of protocol. It inclues major and minor version.

var DefaultVersion Version = [2]uint16{1, 0}

DefaultVersion is default protocol version.

func (Version) Bytes

func (p Version) Bytes() []byte

Bytes returns raw bytes of current version.

func (Version) Major

func (p Version) Major() uint16

Major returns major version.

func (Version) Minor

func (p Version) Minor() uint16

Minor returns minor version.

func (Version) String

func (p Version) String() string

func (Version) WriteTo

func (p Version) WriteTo(w io.Writer) (n int64, err error)

WriteTo write raw version bytes to a writer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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