Documentation ¶
Index ¶
- Variables
- type Conn
- func (c *Conn) EnableWriteCompression(enable bool)
- func (c *Conn) OnClose(h func(*Conn, error))
- func (c *Conn) Session() interface{}
- func (c *Conn) SetCompressionLevel(level int) error
- func (c *Conn) SetSession(session interface{})
- func (c *Conn) Subprotocol() string
- func (c *Conn) Write(data []byte) (int, error)
- func (c *Conn) WriteFrame(messageType MessageType, sendOpcode, fin bool, data []byte) error
- func (c *Conn) WriteMessage(messageType MessageType, data []byte) error
- type Dialer
- type MessageType
- type Upgrader
- type WebsocketReader
- func (wr *WebsocketReader) BlockingModReadLoop()
- func (wr *WebsocketReader) BlockingModWriteLoop()
- func (wr *WebsocketReader) Close(p *nbhttp.Parser, err error)
- func (wr *WebsocketReader) CompressionEnabled() bool
- func (wr *WebsocketReader) EnableCompression(enable bool)
- func (wr *WebsocketReader) EnableWriteCompression(enable bool)
- func (wr *WebsocketReader) OnClose(h func(*Conn, error))
- func (wr *WebsocketReader) OnDataFrame(h func(*Conn, MessageType, bool, []byte))
- func (wr *WebsocketReader) OnMessage(h func(*Conn, MessageType, []byte))
- func (wr *WebsocketReader) OnOpen(h func(*Conn))
- func (wr *WebsocketReader) Read(p *nbhttp.Parser, data []byte) error
- func (wr *WebsocketReader) SetBlockingMod(blocking bool)
- func (wr *WebsocketReader) SetCloseHandler(h func(*Conn, int, string))
- func (wr *WebsocketReader) SetCompressionLevel(level int) error
- func (wr *WebsocketReader) SetConn(conn *Conn)
- func (wr *WebsocketReader) SetPingHandler(h func(*Conn, string))
- func (wr *WebsocketReader) SetPongHandler(h func(*Conn, string))
- func (wr *WebsocketReader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (net.Conn, error)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrUpgradeTokenNotFound . ErrUpgradeTokenNotFound = errors.New("websocket: the client is not using the websocket protocol: 'upgrade' token not found in 'Connection' header") // ErrUpgradeMethodIsGet . ErrUpgradeMethodIsGet = errors.New("websocket: the client is not using the websocket protocol: request method is not GET") // ErrUpgradeInvalidWebsocketVersion . ErrUpgradeInvalidWebsocketVersion = errors.New("websocket: unsupported version: 13 not found in 'Sec-Websocket-Version' header") // ErrUpgradeUnsupportedExtensions . ErrUpgradeUnsupportedExtensions = errors.New("websocket: application specific 'Sec-WebSocket-Extensions' headers are unsupported") // ErrUpgradeOriginNotAllowed . ErrUpgradeOriginNotAllowed = errors.New("websocket: request origin not allowed by Upgrader.CheckOrigin") // ErrUpgradeMissingWebsocketKey . ErrUpgradeMissingWebsocketKey = errors.New("websocket: not a websocket handshake: 'Sec-WebSocket-Key' header is missing or blank") // ErrUpgradeNotHijacker . ErrUpgradeNotHijacker = errors.New("websocket: response does not implement http.Hijacker") // ErrInvalidControlFrame . ErrInvalidControlFrame = errors.New("websocket: invalid control frame") // ErrInvalidWriteCalling . ErrInvalidWriteCalling = errors.New("websocket: invalid write calling, should call WriteMessage instead") // ErrReserveBitSet . ErrReserveBitSet = errors.New("websocket: reserved bit set it frame") // ErrReservedOpcodeSet . ErrReservedOpcodeSet = errors.New("websocket: reserved opcode received") // ErrControlMessageFragmented . ErrControlMessageFragmented = errors.New("websocket: control messages must not be fragmented") // ErrFragmentsShouldNotHaveBinaryOrTextOpcode . ErrFragmentsShouldNotHaveBinaryOrTextOpcode = errors.New("websocket: fragments should not have opcode of text or binary") // ErrInvalidCloseCode . ErrInvalidCloseCode = errors.New("websocket: invalid close code") // ErrBadHandshake . ErrBadHandshake = errors.New("websocket: bad handshake") // ErrInvalidCompression . ErrInvalidCompression = errors.New("websocket: invalid compression negotiation") // ErrMalformedURL . ErrMalformedURL = errors.New("malformed ws or wss URL") // ErrMessageTooLarge. ErrMessageTooLarge = errors.New("message exceeds the configured limit") // ErrMessageSendQuqueIsFull . ErrMessageSendQuqueIsFull = errors.New("message send queue is full") )
View Source
var ( // DefaultBlockingReadBufferSize . DefaultBlockingReadBufferSize = 1024 * 4 // DefaultBlockingModAsyncWrite represents whether create a goroutine to handle writing: // true : create a goroutine to recv buffers and write to conn, default is true; // false: write buffer to the conn directely. DefaultBlockingModAsyncWrite = false // DefaultEngine will be set to a Upgrader.Engine to handle details such as buffers. DefaultEngine = nbhttp.NewEngine(nbhttp.Config{ ReleaseWebsocketPayload: true, }) )
Functions ¶
This section is empty.
Types ¶
type Conn ¶
Conn .
func (*Conn) EnableWriteCompression ¶
EnableWriteCompression .
func (*Conn) SetCompressionLevel ¶
SetCompressionLevel .
func (*Conn) SetSession ¶
func (c *Conn) SetSession(session interface{})
SetSession sets user session.
func (*Conn) Subprotocol ¶
Subprotocol returns the negotiated websocket subprotocol.
func (*Conn) WriteFrame ¶
func (c *Conn) WriteFrame(messageType MessageType, sendOpcode, fin bool, data []byte) error
WriteFrame .
func (*Conn) WriteMessage ¶
func (c *Conn) WriteMessage(messageType MessageType, data []byte) error
WriteMessage .
type Dialer ¶
type Dialer struct { Engine *nbhttp.Engine Upgrader *Upgrader Jar http.CookieJar DialTimeout time.Duration TLSClientConfig *tls.Config Proxy func(*http.Request) (*url.URL, error) CheckRedirect func(req *http.Request, via []*http.Request) error Subprotocols []string EnableCompression bool Cancel context.CancelFunc }
Dialer .
type MessageType ¶
type MessageType int8
MessageType .
const ( // FragmentMessage . FragmentMessage MessageType = 0 // Must be preceded by Text or Binary message // TextMessage . TextMessage MessageType = 1 // BinaryMessage . BinaryMessage MessageType = 2 // CloseMessage . CloseMessage MessageType = 8 // PingMessage . PingMessage MessageType = 9 // PongMessage . PongMessage MessageType = 10 )
The message types are defined in RFC 6455, section 11.8.t .
type WebsocketReader ¶
type WebsocketReader struct { ReadLimit int64 // MessageLengthLimit is the maximum length of websocket message. 0 for unlimited. MessageLengthLimit int64 HandshakeTimeout time.Duration KeepaliveTime time.Duration Subprotocols []string CheckOrigin func(r *http.Request) bool Engine *nbhttp.Engine BlockingModReadBufferSize int BlockingModAsyncWrite bool // contains filtered or unexported fields }
func (*WebsocketReader) BlockingModReadLoop ¶
func (wr *WebsocketReader) BlockingModReadLoop()
BlockingModReadLoop .
func (*WebsocketReader) BlockingModWriteLoop ¶
func (wr *WebsocketReader) BlockingModWriteLoop()
BlockingModWriteLoop .
func (*WebsocketReader) Close ¶
func (wr *WebsocketReader) Close(p *nbhttp.Parser, err error)
Close .
func (*WebsocketReader) CompressionEnabled ¶
func (wr *WebsocketReader) CompressionEnabled() bool
CompressionEnabled .
func (*WebsocketReader) EnableCompression ¶
func (wr *WebsocketReader) EnableCompression(enable bool)
EnableCompression .
func (*WebsocketReader) EnableWriteCompression ¶
func (wr *WebsocketReader) EnableWriteCompression(enable bool)
EnableWriteCompression .
func (*WebsocketReader) OnClose ¶
func (wr *WebsocketReader) OnClose(h func(*Conn, error))
OnClose .
func (*WebsocketReader) OnDataFrame ¶
func (wr *WebsocketReader) OnDataFrame(h func(*Conn, MessageType, bool, []byte))
OnDataFrame .
func (*WebsocketReader) OnMessage ¶
func (wr *WebsocketReader) OnMessage(h func(*Conn, MessageType, []byte))
OnMessage .
func (*WebsocketReader) Read ¶
func (wr *WebsocketReader) Read(p *nbhttp.Parser, data []byte) error
Read .
func (*WebsocketReader) SetBlockingMod ¶
func (wr *WebsocketReader) SetBlockingMod(blocking bool)
SetBlockingMod .
func (*WebsocketReader) SetCloseHandler ¶
func (wr *WebsocketReader) SetCloseHandler(h func(*Conn, int, string))
SetCloseHandler .
func (*WebsocketReader) SetCompressionLevel ¶
func (wr *WebsocketReader) SetCompressionLevel(level int) error
SetCompressionLevel .
func (*WebsocketReader) SetPingHandler ¶
func (wr *WebsocketReader) SetPingHandler(h func(*Conn, string))
SetPingHandler .
func (*WebsocketReader) SetPongHandler ¶
func (wr *WebsocketReader) SetPongHandler(h func(*Conn, string))
SetPongHandler .
Click to show internal directories.
Click to hide internal directories.