websocket

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 7 Imported by: 7

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 added in v0.4.9

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 added in v0.4.8

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

func WithHandshakeTimeout added in v0.4.8

func WithHandshakeTimeout(t time.Duration) Option

func WithReadBufferSize added in v0.4.11

func WithReadBufferSize(size int) Option

func WithReadTimeoutTimeout added in v0.4.8

func WithReadTimeoutTimeout(t time.Duration) Option

func WithWriteBufferSize added in v0.4.11

func WithWriteBufferSize(size int) Option

func WithWriteTimeoutTimeout added in v0.4.8

func WithWriteTimeoutTimeout(t time.Duration) Option

type OptionFunc added in v0.4.8

type OptionFunc func(*recws.RecConn)

func (OptionFunc) Apply added in v0.4.8

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