codec

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// TextMessage denotes a text data message. The text message payload is
	// interpreted as UTF-8 encoded text data.
	TextMessage = 1

	// BinaryMessage denotes a binary data message.
	BinaryMessage = 2

	// CloseMessage denotes a close control message. The optional message
	// payload contains a numeric code and text. Use the FormatCloseMessage
	// function to format a close message payload.
	CloseMessage = 8

	// PingMessage denotes a ping control message. The optional message payload
	// is UTF-8 encoded text.
	PingMessage = 9

	// PongMessage denotes a ping control message. The optional message payload
	// is UTF-8 encoded text.
	PongMessage = 10

	BinaryMessagefinalBit = BinaryMessage | finalBit
)

The message types are defined in RFC 6455, section 11.8.

View Source
const (
	CloseNormalClosure           = 1000
	CloseGoingAway               = 1001
	CloseProtocolError           = 1002
	CloseUnsupportedData         = 1003
	CloseNoStatusReceived        = 1005
	CloseAbnormalClosure         = 1006
	CloseInvalidFramePayloadData = 1007
	ClosePolicyViolation         = 1008
	CloseMessageTooBig           = 1009
	CloseMandatoryExtension      = 1010
	CloseInternalServerErr       = 1011
	CloseServiceRestart          = 1012
	CloseTryAgainLater           = 1013
	CloseTLSHandshake            = 1015
)

Close codes defined in RFC 6455, section 11.7.

Variables

View Source
var ErrCloseSent = errors.New("websocket: close sent")
View Source
var ErrReadLimit = errors.New("websocket: read limit exceeded")
View Source
var Http2pool = sync.Pool{New: func() interface{} {
	hs := &Http2server{}
	hs.ReadPool, _ = ants.NewPool(http2MaxConcurrentStreams)
	hs.SendPool, _ = ants.NewPoolWithFunc(http2MaxConcurrentStreams, sendpool_static)
	hs.Streams = make([]*Http2stream, http2MaxConcurrentStreams)
	hs.Streams[0] = &Http2stream{sendch: make(chan int8), Out: &tls.MsgBuffer{}}
	hs.ReadMetaHeaders = hpack.NewDecoder(http2initialHeaderTableSize, nil)
	hs.Streams[0].svr = hs

	return hs
}}
View Source
var Httppool = sync.Pool{New: func() interface{} {
	hs := &Httpserver{Out: new(tls.MsgBuffer)}
	hs.Request.Header = make(map[string]string)
	hs.data = &bytes.Reader{}
	return hs
}}

Functions

func CompressNoContextTakeover

func CompressNoContextTakeover(w io.WriteCloser, level int) io.ReadWriteCloser

func ComputeAcceptKey

func ComputeAcceptKey(challengeKey string) string

func DecompressNoContextTakeover

func DecompressNoContextTakeover(r io.Reader) io.ReadCloser

func FormatCloseMessage

func FormatCloseMessage(closeCode int, text string) []byte

FormatCloseMessage formats closeCode and text as a WebSocket close message.

func GenerateChallengeKey

func GenerateChallengeKey() (string, error)

Types

type CloseError

type CloseError struct {

	// Code is defined in RFC 6455, section 11.7.
	Code int

	// Text is the optional text payload.
	Text string
}

CloseError represents close frame.

func (*CloseError) Error

func (e *CloseError) Error() string

type Http2server

type Http2server struct {
	InHeader http2FrameHeader
	Setting  struct {
		HEADER_TABLE_SIZE            int   //允许发送者以八位字节的形式通知远程端点用于解码头块的头压缩表的最大尺寸。编码器可以通过使用特定于头部块内头部压缩格式的信令来选择等于或小于此值的任何大小
		ENABLE_PUSH                  bool  //此设置可用于禁用服务器推送
		SETTINGS_INITIAL_WINDOW_SIZE int32 //初始化默认的窗口大小
		MAX_FRAME_SIZE               int   //指示发送者愿意接收的最大帧有效载荷的大小
		MAX_HEADER_LIST_SIZE         int   //此通报设置以八位字节的形式通知对等方发送方准备接受的标题列表的最大大小
	}
	WorkStream      *Http2stream
	ReadPool        *ants.Pool
	SendPool        *ants.PoolWithFunc
	Streams         []*Http2stream
	ReadMetaHeaders *hpack.Decoder
	// contains filtered or unexported fields
}

func NewH2Conn

func NewH2Conn(c gnet.Conn) *Http2server

初始化一个连接

func (*Http2server) Close

func (h2s *Http2server) Close()

type Http2stream

type Http2stream struct {
	Out                             *tls.MsgBuffer
	Headers                         []hpack.HeaderField
	In                              *tls.MsgBuffer
	Id                              uint32
	IN_WINDOW_SIZE, OUT_WINDOW_SIZE int32
	// contains filtered or unexported fields
}

func (*Http2stream) Out404Frame

func (stream *Http2stream) Out404Frame(err error)

func (*Http2stream) RandOut added in v1.1.6

func (stream *Http2stream) RandOut()

func (*Http2stream) WriteData

func (stream *Http2stream) WriteData(reader io.Reader, length int)

type Httpserver

type Httpserver struct {
	Request Request

	Out *tls.MsgBuffer
	Ws  *WSconn
	// contains filtered or unexported fields
}

func (*Httpserver) Ip

func (hs *Httpserver) Ip(c gnet.Conn) (ip string)

func (*Httpserver) IsMobile

func (hs *Httpserver) IsMobile() bool

func (*Httpserver) Lastvisit

func (hs *Httpserver) Lastvisit() int32

func (*Httpserver) Out404

func (hs *Httpserver) Out404(err error)

func (*Httpserver) Output_data

func (hs *Httpserver) Output_data(bin []byte)

func (*Httpserver) RandOut added in v1.1.6

func (hs *Httpserver) RandOut()

func (*Httpserver) SetLastvisit

func (hs *Httpserver) SetLastvisit(int32)

func (*Httpserver) Static

func (hs *Httpserver) Static()

func (*Httpserver) Upgradews

func (hs *Httpserver) Upgradews(c gnet.Conn) (err error)

http升级为websocket

func (*Httpserver) UserAgent

func (hs *Httpserver) UserAgent() string

type Request

type Request struct {
	Proto, Method string
	Path, Query   string
	RemoteAddr    string
	Connection    string
	Header        map[string]string
}

func (*Request) GetHeader

func (r *Request) GetHeader(key string) string

func (*Request) Parsereq

func (req *Request) Parsereq(data []byte) (n int, out []byte, err error)

type Tlscodec

type Tlscodec struct {
}

func (*Tlscodec) Decode

func (code *Tlscodec) Decode(c gnet.Conn) (data []byte, err error)

func (*Tlscodec) Encode

func (code *Tlscodec) Encode(c gnet.Conn, buf []byte) ([]byte, error)

type WSconn

type WSconn struct {
	Http *Httpserver
	//以下是发送接收相关
	IsCompress bool

	ReadFinal  bool // true the current message has more frames.
	ReadLength int  // Message size.

	IsServer bool
	Write    func([]byte) error

	Ctx interface{}
	// contains filtered or unexported fields
}

func (*WSconn) Output_data

func (c *WSconn) Output_data(msg *tls.MsgBuffer)

func (*WSconn) ReadMessage

func (c *WSconn) ReadMessage(in []byte) (frameType int, result []byte, err error)

func (*WSconn) WriteMessage

func (c *WSconn) WriteMessage(messageType int, data []byte) error

Jump to

Keyboard shortcuts

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