websocket

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxHeaderSize = 14
)

Header size length bounds in bytes.

Variables

View Source
var (
	ErrHeaderLengthMSB        = fmt.Errorf("header error: the most significant bit must be 0")
	ErrHeaderLengthUnexpected = fmt.Errorf("header error: unexpected payload length bits")
	ErrHeaderNotReady         = fmt.Errorf("header error: not enough")
)

Errors used by frame reader.

Functions

func CheckCloseFrameData

func CheckCloseFrameData(code ws.StatusCode, reason string) error

CheckCloseFrameData checks received close information to be valid RFC6455 compatible close info.

Note that code.Empty() or code.IsAppLevel() will raise error.

If endpoint sends close frame without status code (with frame.Length = 0), application should not check its payload.

func HandleCloseFrame

func HandleCloseFrame(pool *pbytes.Pool, body *bytes.Buffer, buffer *bytes.Buffer) error

func NewWebSocketServer added in v0.2.1

func NewWebSocketServer(handler WSHandler, opts ...gev.Option) (server *gev.Server, err error)

NewWebSocketServer 创建 WebSocket Server

func ParseCloseFrameData

func ParseCloseFrameData(payload []byte) (code ws.StatusCode, reason string)

ParseCloseFrameData parses close frame status code and closure reason if any provided. If there is no status code in the payload the empty status code is returned (code.Empty()) with empty string as a reason.

func VirtualReadHeader

func VirtualReadHeader(pool *pbytes.Pool, in *ringbuffer.RingBuffer) (h ws.Header, err error)

VirtualReadHeader reads a frame header from r.

func WriteBinaryFrame

func WriteBinaryFrame(pool *pbytes.Pool, body *bytes.Buffer, buffer *bytes.Buffer) error

func WritePongFrame

func WritePongFrame(pool *pbytes.Pool, body *bytes.Buffer, buffer *bytes.Buffer) error

Types

type HandlerWrap

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

HandlerWrap gev Handler wrap

func NewHandlerWrap

func NewHandlerWrap(wsHandler WSHandler) *HandlerWrap

func (*HandlerWrap) OnClose

func (s *HandlerWrap) OnClose(c *gev.Connection)

func (*HandlerWrap) OnConnect

func (s *HandlerWrap) OnConnect(c *gev.Connection)

func (*HandlerWrap) OnMessage

func (s *HandlerWrap) OnMessage(c *gev.Connection, buffer *ringbuffer.RingBuffer)

type WSHandler

type WSHandler interface {
	OnConnect(c *gev.Connection)
	OnMessage(c *gev.Connection, msg []byte, outBuffer *bytes.Buffer) error
	OnClose(c *gev.Connection)
}

WSHandler WebSocket Server 注册接口

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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