wsp

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Timeout     time.Duration
	IdleTimeout time.Duration
	SecretKey   string
}

type Connection

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

Connection manages a single websocket connection from the peer. wsp supports multiple connections from a single peer at the same time.

func NewConnection

func NewConnection(pool *Pool, ws *websocket.Conn) *Connection

NewConnection returns a new Connection.

func (*Connection) Close

func (c *Connection) Close()

Close the connection

func (*Connection) Release

func (c *Connection) Release()

Release notifies that this connection is ready to use again

func (*Connection) Take

func (c *Connection) Take() bool

Take notifies that this connection is going to be used

func (*Connection) WritePump added in v0.13.1

func (c *Connection) WritePump()

type ConnectionStatus

type ConnectionStatus int

ConnectionStatus is an enumeration type which represents the status of WebSocket connection.

const (
	// Idle state means it is opened but not working now.
	// The default value for Connection is Idle, so it is ok to use zero-value(int: 0) for Idle status.
	Idle ConnectionStatus = iota
	Busy
	Closed
)

type Message added in v0.13.1

type Message struct {
	Type  int
	Value []byte
}

type Pool

type Pool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Pool handles all connections from the peer.

func NewPool

func NewPool(timeout, idleTimeout time.Duration, id PoolID) *Pool

NewPool creates a new Pool

func (*Pool) Clean

func (p *Pool) Clean()

func (*Pool) GetIdleConnection added in v0.14.0

func (p *Pool) GetIdleConnection(ctx context.Context) (conn *Connection)

func (*Pool) IsEmpty

func (p *Pool) IsEmpty() bool

IsEmpty clean the pool and return true if the pool is empty

func (*Pool) Offer

func (p *Pool) Offer(connection *Connection)

func (*Pool) RegisterConnection added in v0.14.0

func (p *Pool) RegisterConnection(ws *websocket.Conn)

RegisterConnection creates a new Connection and adds it to the pool

func (*Pool) SetSize added in v0.14.0

func (p *Pool) SetSize(size int)

func (*Pool) Shutdown

func (p *Pool) Shutdown()

Shutdown closes every connections in the pool and cleans it

func (*Pool) Size

func (p *Pool) Size() (ps *PoolSize)

Size return the number of connection in each state in the pool

type PoolID

type PoolID string

PoolID represents the identifier of the connected WebSocket client.

type PoolSize

type PoolSize struct {
	Idle   int
	Busy   int
	Closed int
}

PoolSize is the number of connection in each state in the pool

type Pools added in v0.14.0

type Pools struct {
	*sync.Mutex
	// contains filtered or unexported fields
}

func NewPools added in v0.14.0

func NewPools(timeout, idleTimeout time.Duration) *Pools

func (*Pools) Clean added in v0.14.0

func (p *Pools) Clean()

func (*Pools) GetPool added in v0.14.0

func (p *Pools) GetPool(id PoolID) (pool *Pool, ok bool)

func (*Pools) IsEmpty added in v0.14.0

func (p *Pools) IsEmpty() bool

func (*Pools) MoreThenOne added in v0.14.0

func (p *Pools) MoreThenOne() bool

func (*Pools) RegisterConnection added in v0.14.0

func (p *Pools) RegisterConnection(ws *websocket.Conn) (err error)

func (*Pools) Shutdown added in v0.14.0

func (p *Pools) Shutdown()

type Server

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

Server is a Reverse HTTP Proxy over WebSocket This is the Server part, Clients will offer websocket connections, those will be pooled to transfer HTTP Request and response

func NewServer

func NewServer(config *Config) (server *Server)

func (*Server) GetServerID

func (s *Server) GetServerID(r *http.Request) (serverID string, err error)

func (*Server) Register

func (s *Server) Register(w http.ResponseWriter, r *http.Request)

Request receives the WebSocket upgrade handshake request from wsp_client.

func (*Server) Request

func (s *Server) Request(w http.ResponseWriter, r *http.Request)

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown stop the Server

func (*Server) Start

func (s *Server) Start()

Start Server HTTP server

func (*Server) Ws

func (s *Server) Ws(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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