Documentation
¶
Index ¶
- Constants
- Variables
- func WithListeners(count int) option
- func WithReadBufferSize(size int) option
- func WithReadDeadline(deadline time.Duration) option
- func WithWriteBufferDeadline(deadline time.Duration) option
- func WithWriteBufferSize(size int) option
- type CloseStatus
- type Conn
- func (c *Conn) CloseImmediatelyWith(status CloseStatus, reason string, disconnect bool) error
- func (c *Conn) CloseWith(status CloseStatus, reason string, disconnect bool) error
- func (c *Conn) Get() any
- func (c *Conn) Set(value any)
- func (c *Conn) Write(b []byte) (int, error)
- func (c *Conn) WriteText(s string) (int, error)
- type Handler
- type Server
Constants ¶
const ( HeapRemoved = -1 HeapUnassigned = -2 )
const ( DefaultBufferSize = 1 << 14 DefaultBufferFlushDeadline = time.Millisecond * 50 DefaultReadDeadline = time.Second )
Variables ¶
var ( ErrHeaderLengthMSB = fmt.Errorf("header error: the most significant bit must be 0") ErrHeaderLengthUnexpected = fmt.Errorf("header error: unexpected payload length bits") )
var ( ErrDataNeeded = errors.New("not enough data to continue") ErrConnectionAlreadyClosed = errors.New("connection already closed") ErrConnectionTimeout = &closeError{ Status: CloseStatusAbnormalClosure, Reason: "connection timeout", } ErrInvalidRSVBits error = &closeError{ Status: CloseStatusProtocolError, Reason: "non-zero rsv bits not supported", } ErrInvalidOpCode error = &closeError{ Status: CloseStatusProtocolError, Reason: "invalid or reserved op code", } ErrInvalidContinuation error = &closeError{ Status: CloseStatusProtocolError, Reason: "invalid continuation", } ErrInvalidPayloadEncoding error = &closeError{ Status: CloseStatusInvalidFramePayloadData, Reason: "close frame reason invalid", immediate: true, } ErrInvalidControlLength error = &closeError{ Status: CloseStatusProtocolError, Reason: "control frame payload exceeds 125 bytes", immediate: true, shutdown: true, } ErrInvalidCloseReason error = &closeError{ Status: CloseStatusProtocolError, Reason: "close frame reason invalid", immediate: true, shutdown: true, } ErrInvalidCloseEncoding error = &closeError{ Status: CloseStatusInvalidFramePayloadData, Reason: "close frame reason invalid", immediate: true, shutdown: true, } )
Functions ¶
func WithListeners ¶
func WithListeners(count int) option
WithListeners sets the number of listeners, defaults to GOMAXPROCS
func WithReadBufferSize ¶
func WithReadBufferSize(size int) option
WithReadBufferSize sets the size of read buffer used for a connection
func WithReadDeadline ¶
WithReadDeadline sets the read deadline option when reading from sockets that have data available
func WithWriteBufferDeadline ¶
WithWriteBufferDeadline sets the timeout for flushing the buffer to the underlying connection
func WithWriteBufferSize ¶
func WithWriteBufferSize(size int) option
WithWriteBufferSize sets the size of write buffer used for a connection when the buffer exceeds this size, it will be flushed
Types ¶
type CloseStatus ¶
type CloseStatus uint64
const ( CloseStatusNormalClosure CloseStatus = 1000 CloseStatusGoingAway CloseStatus = 1001 CloseStatusProtocolError CloseStatus = 1002 CloseStatusUnsupportedData CloseStatus = 1003 CloseStatusNoStatusReceived CloseStatus = 1005 CloseStatusAbnormalClosure CloseStatus = 1006 CloseStatusInvalidFramePayloadData CloseStatus = 1007 CloseStatusPolicyViolation CloseStatus = 1008 CloseStatusMessageTooBig CloseStatus = 1009 CloseStatusMandatoryExtension CloseStatus = 1010 CloseStatusInternalServerErr CloseStatus = 1011 CloseStatusServiceRestart CloseStatus = 1012 CloseStatusTryAgainLater CloseStatus = 1013 CloseStatusTLSHandshake CloseStatus = 1015 )
type Conn ¶
A wrapped net.Conn with on demand buffers that implements the net.Conn interface
func (*Conn) CloseImmediatelyWith ¶
func (c *Conn) CloseImmediatelyWith(status CloseStatus, reason string, disconnect bool) error
CloseImmediatelyWith sends close frame to the connection immediately, discarding any buffered state. if disconnect is specified as true, the underlying connection will be closed immediately
func (*Conn) CloseWith ¶
func (c *Conn) CloseWith(status CloseStatus, reason string, disconnect bool) error
CloseWith writes all existing buffered state and sends close frame to the connection. if disconnect is specified as true, the underlying connection will be closed immediately
type Handler ¶
type Handler struct {
// OnConnect is invoked upon a new connection
OnConnect func(conn *Conn)
// OnDisconnect is invoked when an existing connection disconnects
OnDisconnect func(conn *Conn, err error)
// OnPing is invoked when a connection sends a websocket ping frame
OnPing func(conn *Conn)
// OnPong is invoked when a connection sends a websocket pong frame
OnPong func(conn *Conn)
// OnMessage is invoked when a connection sends either a text or
// binary message. the msg buffer that is passed is only safe for
// use until the callback returns
OnMessage func(conn *Conn, msg []byte)
// OnBinary is invoked when a connection sends a binary message.
// the msg buffer that is passed is only safe for use until the
// callback returns
OnBinary func(conn *Conn, msg []byte)
// OnText is invoked when a connection sends a text message.
// the msg buffer that is passed is only safe for use until the
// callback returns
OnText func(conn *Conn, msg string)
// OnError is invoked when an error occurs
OnError func(err error, isFatal bool)
}