Documentation
¶
Overview ¶
Package uws provides an asynchronous WebSocket server built on UIO.
Index ¶
- Constants
- Variables
- type CloseInfo
- type Conn
- func (c *Conn) BeginMessage(typ MessageType) (*Writer, error)
- func (c *Conn) Close(code uint16, reason string) error
- func (c *Conn) Context() any
- func (c *Conn) IsClosed() bool
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Ping(payload []byte) error
- func (c *Conn) Ready() <-chan error
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SendBinary(payload []byte) error
- func (c *Conn) SendText(payload []byte) error
- func (c *Conn) SetContext(ctx any)
- func (c *Conn) Subprotocol() string
- type Dialer
- type Executor
- type Handler
- type Message
- type MessageType
- type Server
- type Writer
Constants ¶
const ( DefaultMaxHeaderBytes = handshake.DefaultMaxBytes DefaultMaxFramePayload = 16 << 20 DefaultMaxMessageSize = 64 << 20 // Leave room for the largest legal WebSocket frame header (including a // client mask) so a maximum-sized default frame is not rejected by the // outbound budget before it reaches the transport. DefaultMaxOutboundBytes = DefaultMaxFramePayload + 14 DefaultCloseTimeout = 5 * time.Second DefaultHandshakeTimeout = 10 * time.Second DefaultSlowClientTimeout = 30 * time.Second DefaultMaxPendingMessages = 64 DefaultMaxPendingBytes = 1 << 20 DefaultMaxPendingTotalMessages = 4096 DefaultMaxPendingTotalBytes = 64 << 20 )
Variables ¶
var ( ErrClosed = errors.New("uws: connection closed") ErrNotReady = errors.New("uws: handshake not complete") ErrBackpressure = errors.New("uws: outbound queue is full") ErrApplicationBackpressure = errors.New("uws: application queue is full") ErrExecutorRejected = errors.New("uws: executor rejected callback") ErrWriterClosed = errors.New("uws: message writer is closed") ErrProtocol = frame.ErrProtocol )
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
func (*Conn) BeginMessage ¶
func (c *Conn) BeginMessage(typ MessageType) (*Writer, error)
BeginMessage starts a fragmented message and holds the connection's write ownership until Writer.Close returns. It is non-blocking with respect to the socket; callers must always close the returned writer. With compression enabled, writes are compressed incrementally and emitted as continuation frames, so large messages do not need a second full plaintext buffer.
func (*Conn) Ready ¶
Ready returns a one-shot result for the WebSocket handshake. A nil error means the connection is ready for Send or BeginMessage.
func (*Conn) RemoteAddr ¶
func (*Conn) SendBinary ¶
func (*Conn) SetContext ¶
func (*Conn) Subprotocol ¶
type Dialer ¶
type Dialer struct {
Events *uio.Events
Subprotocols []string
MaxHeaderBytes int
MaxFramePayload uint64
MaxMessageSize uint64
MaxOutboundBytes int
EnableCompression bool
CompressionLevel int
// CloseTimeout bounds the graceful WebSocket close handshake. A zero value
// uses DefaultCloseTimeout.
CloseTimeout time.Duration
// HandshakeTimeout bounds the HTTP upgrade handshake. A zero value uses
// DefaultHandshakeTimeout.
HandshakeTimeout time.Duration
// SlowClientTimeout closes FullDuplex connections that remain blocked on
// socket writes. A zero value uses DefaultSlowClientTimeout.
SlowClientTimeout time.Duration
// Executor dispatches OnOpen, OnMessage, and OnClose callbacks away from
// the I/O event loop. A nil executor preserves synchronous callbacks.
Executor Executor
// MaxPendingMessages bounds queued application messages per connection when
// Executor is enabled. Zero uses DefaultMaxPendingMessages.
MaxPendingMessages int
// MaxPendingBytes bounds queued application payload bytes per connection
// when Executor is enabled. Zero uses DefaultMaxPendingBytes.
MaxPendingBytes int
// MaxPendingTotalMessages bounds queued application messages across all
// connections using this dialer. Zero uses DefaultMaxPendingTotalMessages.
MaxPendingTotalMessages int
// MaxPendingTotalBytes bounds queued application payload bytes across all
// connections using this dialer. Zero uses DefaultMaxPendingTotalBytes.
MaxPendingTotalBytes int
// contains filtered or unexported fields
}
type Executor ¶
type Executor interface {
Submit(func()) bool
}
Executor runs application callbacks outside the I/O event loop. Submit must return promptly and reports false when a bounded worker queue is full.
type Handler ¶
type Handler interface {
// OnOpen and OnClose are called once around a successful WebSocket
// handshake. OnMessage is ordered per connection. With Executor enabled,
// all three callbacks for one connection are serialized by that executor.
OnOpen(*Conn)
OnMessage(*Conn, Message)
OnClose(*Conn, CloseInfo)
}
type Message ¶
type Message struct {
Type MessageType
// Payload is valid until OnMessage returns. Call Clone before retaining it
// or handing it to another goroutine.
Payload []byte
}
type MessageType ¶
type MessageType uint8
const ( TextMessage MessageType = 1 BinaryMessage MessageType = 2 )
type Server ¶
type Server struct {
Events *uio.Events
Handler Handler
CheckOrigin func(*http.Request) bool
Subprotocols []string
MaxHeaderBytes int
MaxFramePayload uint64
MaxMessageSize uint64
MaxOutboundBytes int
EnableCompression bool
CompressionLevel int
// CloseTimeout bounds the graceful WebSocket close handshake. A zero value
// uses DefaultCloseTimeout.
CloseTimeout time.Duration
// HandshakeTimeout bounds the HTTP upgrade handshake. A zero value uses
// DefaultHandshakeTimeout.
HandshakeTimeout time.Duration
// SlowClientTimeout closes FullDuplex connections that remain blocked on
// socket writes. A zero value uses DefaultSlowClientTimeout.
SlowClientTimeout time.Duration
// Executor dispatches OnOpen, OnMessage, and OnClose callbacks away from
// the I/O event loop. A nil executor preserves synchronous callbacks.
Executor Executor
// MaxPendingMessages bounds queued application messages per connection when
// Executor is enabled. Zero uses DefaultMaxPendingMessages.
MaxPendingMessages int
// MaxPendingBytes bounds queued application payload bytes per connection
// when Executor is enabled. Zero uses DefaultMaxPendingBytes.
MaxPendingBytes int
// MaxPendingTotalMessages bounds queued application messages across all
// connections using this server. Zero uses DefaultMaxPendingTotalMessages.
MaxPendingTotalMessages int
// MaxPendingTotalBytes bounds queued application payload bytes across all
// connections using this server. Zero uses DefaultMaxPendingTotalBytes.
MaxPendingTotalBytes int
// AllowCompressionContextTakeover enables RFC 7692 context takeover for
// peers that do not request a no-context-takeover parameter. It is disabled
// by default to bound per-connection compression state.
AllowCompressionContextTakeover bool
HeartbeatInterval time.Duration
HeartbeatTimeout time.Duration
// contains filtered or unexported fields
}