mux

package module
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 11 Imported by: 0

README

GoDoc MIT licensed Build Status Go Report Card Coverage Statusd Sourcegraph

Mux is a multiplexing library for golang. It used to combine multi transfer connection into a single one to reduce system load and make connection handshake faster.

Documentation

Index

Constants

View Source
const (
	RoleClient roleType = 1 + iota // client start with odd number, server start with even number
	RoleServer
)

Variables

View Source
var (
	BufferSizeLimitErr = errors.New("buffer size limit err")
	UnknownCmdErr      = errors.New("cmd unknown err")
)
View Source
var (
	NoopLogger     = &noopLoggerImpl{}
	StandardLogger = &standardLoggerImpl{}
)
View Source
var (
	ErrSessionClosed    = errors.New("session closed")
	ErrSessionTTLExceed = errors.New("session ttl exceed")
	ErrStreamIdDup      = errors.New("stream id duplicated err")
	ErrStreamIdNotFound = errors.New("stream id not found")
	ErrBufferLimited    = errors.New("buffer length limited")
)
View Source
var (
	ErrStreamClosed = errors.New("stream has been closed")
)

Functions

This section is empty.

Types

type BufferAllocFunc added in v0.0.14

type BufferAllocFunc func(size int) []byte

type BufferRecycleFunc added in v0.0.14

type BufferRecycleFunc func([]byte)

type Frame

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

func NewFrameContext added in v0.0.27

func NewFrameContext(ctx context.Context, cmd cmdType, streamId uint32, data []byte) *Frame

func (*Frame) Close

func (frame *Frame) Close()

func (*Frame) Cmd

func (frame *Frame) Cmd() byte

func (*Frame) MarshalHeader added in v0.0.28

func (frame *Frame) MarshalHeader(buffer []byte) (int, error)

func (*Frame) StreamId

func (frame *Frame) StreamId() uint32

func (*Frame) UnMarshalHeader added in v0.0.28

func (frame *Frame) UnMarshalHeader(buffer []byte) (int, error)

type Logger added in v0.4.3

type Logger interface {
	Debugf(_ string, _ ...interface{})
	Infof(_ string, _ ...interface{})
	Warnf(_ string, _ ...interface{})
	Errorf(_ string, _ ...interface{})
}

type Option added in v0.0.14

type Option func(*Session)

func WithBufferManager added in v0.0.42

func WithBufferManager(allocFunc BufferAllocFunc, recycleFunc BufferRecycleFunc) Option

func WithBufferSize added in v0.0.27

func WithBufferSize(sizeLimit int) Option

func WithFinalizer added in v0.3.5

func WithFinalizer(finalizer func()) Option

func WithHeartBeatInterval added in v0.0.29

func WithHeartBeatInterval(interval time.Duration) Option

func WithHeartBeatSwitch added in v0.0.29

func WithHeartBeatSwitch(choose bool) Option

func WithHeartBeatTTL added in v0.3.2

func WithHeartBeatTTL(ttl time.Duration) Option

func WithLogger added in v0.4.3

func WithLogger(logger Logger) Option

func WithMetrics added in v0.4.2

func WithMetrics(writeFrameDurations, recvFrameDurations, acceptStreamDurations prometheus.Histogram) Option

func WithRole added in v0.0.14

func WithRole(role roleType) Option

type Session

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

func NewSession

func NewSession(conn io.ReadWriteCloser, options ...Option) *Session

func NewSessionContext added in v0.0.15

func NewSessionContext(ctx context.Context, conn io.ReadWriteCloser, options ...Option) *Session

func (*Session) AcceptStream

func (session *Session) AcceptStream(ctx context.Context) (*Stream, error)

func (*Session) Close

func (session *Session) Close() error

func (*Session) CloseWithErr

func (session *Session) CloseWithErr(err error)

func (*Session) Ctx added in v0.0.19

func (session *Session) Ctx() context.Context

func (*Session) Err added in v0.3.6

func (session *Session) Err() error

func (*Session) IsClose

func (session *Session) IsClose() bool

func (*Session) Lifetime added in v0.0.22

func (session *Session) Lifetime() time.Duration

func (*Session) OpenStream

func (session *Session) OpenStream(ctx context.Context) (*Stream, error)

OpenStream create a new established stream connection

func (*Session) StreamCount added in v0.0.26

func (session *Session) StreamCount() int

type Stream

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

func (*Stream) Close

func (stream *Stream) Close() error

Close positive close, need to notify remote

func (*Stream) Done added in v0.0.15

func (stream *Stream) Done() <-chan struct{}

func (*Stream) IsClose

func (stream *Stream) IsClose() bool

func (*Stream) Lifetime added in v0.1.0

func (stream *Stream) Lifetime() time.Duration

func (*Stream) LocalAddr added in v0.0.27

func (stream *Stream) LocalAddr() net.Addr

func (*Stream) Read

func (stream *Stream) Read(buffer []byte) (int, error)

func (*Stream) ReadContext added in v0.0.40

func (stream *Stream) ReadContext(ctx context.Context, buffer []byte) (int, error)

func (*Stream) RemoteAddr added in v0.0.27

func (stream *Stream) RemoteAddr() net.Addr

func (*Stream) SetDeadline added in v0.0.27

func (stream *Stream) SetDeadline(t time.Time) error

func (*Stream) SetReadDeadline added in v0.0.27

func (stream *Stream) SetReadDeadline(t time.Time) error

func (*Stream) SetWriteDeadline added in v0.0.27

func (stream *Stream) SetWriteDeadline(t time.Time) error

func (*Stream) Write

func (stream *Stream) Write(buffer []byte) (int, error)

func (*Stream) WriteContext added in v0.0.40

func (stream *Stream) WriteContext(ctx context.Context, buffer []byte) (int, error)

Jump to

Keyboard shortcuts

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