websocket

package
v0.4.14 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2022 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed = errors.New("pool is closed")
)

Functions

func Close

func Close()

func SendWsRequest

func SendWsRequest(c WsConn, v interface{}, action []byte) (err error)

func SetChannelPoolMaxCap

func SetChannelPoolMaxCap(max int)

SetChannelPoolMaxCap set connection pool max cap

func SetEndpoint

func SetEndpoint(endpoint string)

Types

type Factory

type Factory func() (*recws.RecConn, error)

type Option

type Option interface {
	Apply(*recws.RecConn)
}

func WithHandshakeTimeout

func WithHandshakeTimeout(t time.Duration) Option

func WithReadBufferSize

func WithReadBufferSize(size int) Option

func WithReadTimeoutTimeout

func WithReadTimeoutTimeout(t time.Duration) Option

func WithWriteBufferSize

func WithWriteBufferSize(size int) Option

func WithWriteTimeoutTimeout

func WithWriteTimeoutTimeout(t time.Duration) Option

type OptionFunc

type OptionFunc func(*recws.RecConn)

func (OptionFunc) Apply

func (f OptionFunc) Apply(conn *recws.RecConn)

type Pool

type Pool interface {
	Get() (*PoolConn, error)
	Close()
	Len() int
}

func NewChannelPool

func NewChannelPool(initialCap, maxCap int, factory Factory) (Pool, error)

type PoolConn

type PoolConn struct {
	Conn *recws.RecConn
	// contains filtered or unexported fields
}

func Init

func Init(options ...Option) (*PoolConn, error)

func (*PoolConn) Close

func (p *PoolConn) Close() error

Close() puts the given connects back to the pool instead of closing it.

func (*PoolConn) MarkUnusable

func (p *PoolConn) MarkUnusable()

MarkUnusable() marks the connection not usable any more, to let the pool close it instead of returning it to pool.

type WsConn

type WsConn interface {
	Dial(urlStr string, reqHeader http.Header)
	IsConnected() bool
	Close()
	WriteMessage(messageType int, data []byte) error
	ReadMessage() (messageType int, message []byte, err error)
	WriteJSON(v interface{}) error
	ReadJSON(v interface{}) error
	MarkUnusable()
	CloseAndReconnect()
}

Jump to

Keyboard shortcuts

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