Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeCloseCode(cc CloseCode) []byte
- func EncodeCloseFramePayload(cc CloseCode, reason string) []byte
- func GenMask(b []byte)
- func IsReserved(op Opcode) bool
- func IsUpgradeReq(req *http.Request) bool
- func IsUpgradeRes(res *http.Response) bool
- func MakeRequestKey() string
- func MakeResponseKey(reqKey []byte) string
- func Mask(mask, b []byte)
- func ReleaseFrame(f *Frame)
- type AsyncFrameHandler
- type AsyncMessageHandler
- type CloseCode
- type ControlCallback
- type Frame
- func (f *Frame) ExtraHeaderLen() (n int)
- func (f *Frame) IsBinary() bool
- func (f *Frame) IsClose() bool
- func (f *Frame) IsContinuation() bool
- func (f *Frame) IsControl() bool
- func (f *Frame) IsFin() bool
- func (f *Frame) IsMasked() bool
- func (f *Frame) IsPing() bool
- func (f *Frame) IsPong() bool
- func (f *Frame) IsRSV1() bool
- func (f *Frame) IsRSV2() bool
- func (f *Frame) IsRSV3() bool
- func (f *Frame) IsText() bool
- func (f *Frame) Mask()
- func (f *Frame) MaskKey() []byte
- func (f *Frame) Opcode() Opcode
- func (f *Frame) Payload() []byte
- func (f *Frame) PayloadLen() int
- func (f *Frame) PayloadLenType() int
- func (f *Frame) ReadFrom(r io.Reader) (nt int64, err error)
- func (f *Frame) Reset()
- func (f *Frame) SetBinary()
- func (f *Frame) SetClose()
- func (f *Frame) SetContinuation()
- func (f *Frame) SetFin()
- func (f *Frame) SetOpcode(c Opcode)
- func (f *Frame) SetPayload(b []byte)
- func (f *Frame) SetPayloadLen() (bytes int)
- func (f *Frame) SetPing()
- func (f *Frame) SetPong()
- func (f *Frame) SetRSV1()
- func (f *Frame) SetRSV2()
- func (f *Frame) SetRSV3()
- func (f *Frame) SetText()
- func (f *Frame) String() string
- func (f *Frame) Unmask()
- func (f *Frame) WriteTo(w io.Writer) (n int64, err error)
- type FrameCodec
- type Header
- type MessageType
- type MockServer
- type MockStream
- func (s *MockStream) AsyncClose(cb func(err error))
- func (s *MockStream) AsyncRead(b []byte, cb sonic.AsyncCallback)
- func (s *MockStream) AsyncReadAll(b []byte, cb sonic.AsyncCallback)
- func (s *MockStream) AsyncWrite(b []byte, cb sonic.AsyncCallback)
- func (s *MockStream) AsyncWriteAll(b []byte, cb sonic.AsyncCallback)
- func (s *MockStream) Cancel()
- func (s *MockStream) Close() error
- func (s *MockStream) RawFd() int
- func (s *MockStream) Read(b []byte) (n int, err error)
- func (s *MockStream) Write(b []byte) (n int, err error)
- type Opcode
- type ReasonString
- type Role
- type Stream
- type StreamState
- type UpgradeRequestCallback
- type UpgradeResponseCallback
- type WebsocketStream
- func (s *WebsocketStream) Accept() error
- func (s *WebsocketStream) AsyncAccept(func(error))
- func (s *WebsocketStream) AsyncClose(cc CloseCode, reason string, cb func(err error))
- func (s *WebsocketStream) AsyncFlush(cb func(err error))
- func (s *WebsocketStream) AsyncHandshake(addr string, cb func(error), extraHeaders ...Header)
- func (s *WebsocketStream) AsyncNextFrame(cb AsyncFrameHandler)
- func (s *WebsocketStream) AsyncNextMessage(b []byte, cb AsyncMessageHandler)
- func (s *WebsocketStream) AsyncWrite(b []byte, mt MessageType, cb func(err error))
- func (s *WebsocketStream) AsyncWriteFrame(f *Frame, cb func(err error))
- func (s *WebsocketStream) Close(cc CloseCode, reason string) error
- func (s *WebsocketStream) CloseNextLayer() (err error)
- func (s *WebsocketStream) ControlCallback() ControlCallback
- func (s *WebsocketStream) Flush() (err error)
- func (s *WebsocketStream) Handshake(addr string, extraHeaders ...Header) (err error)
- func (s *WebsocketStream) LocalAddr() net.Addr
- func (s *WebsocketStream) NextFrame() (f *Frame, err error)
- func (s *WebsocketStream) NextLayer() sonic.Stream
- func (s *WebsocketStream) NextMessage(b []byte) (mt MessageType, readBytes int, err error)
- func (s *WebsocketStream) Pending() int
- func (s *WebsocketStream) RawFd() int
- func (s *WebsocketStream) RemoteAddr() net.Addr
- func (s *WebsocketStream) SetControlCallback(ccb ControlCallback)
- func (s *WebsocketStream) SetMaxMessageSize(bytes int)
- func (s *WebsocketStream) SetUpgradeRequestCallback(upReqCb UpgradeRequestCallback)
- func (s *WebsocketStream) SetUpgradeResponseCallback(upResCb UpgradeResponseCallback)
- func (s *WebsocketStream) State() StreamState
- func (s *WebsocketStream) SupportsDeflate() bool
- func (s *WebsocketStream) SupportsUTF8() bool
- func (s *WebsocketStream) UpgradeRequestCallback() UpgradeRequestCallback
- func (s *WebsocketStream) UpgradeResponseCallback() UpgradeResponseCallback
- func (s *WebsocketStream) Write(b []byte, mt MessageType) error
- func (s *WebsocketStream) WriteFrame(f *Frame) error
Constants ¶
const ( TypeText = MessageType(OpcodeText) TypeBinary = MessageType(OpcodeBinary) TypeClose = MessageType(OpcodeClose) TypePing = MessageType(OpcodePing) TypePong = MessageType(OpcodePong) TypeNone MessageType = 0xFF )
const MaxControlFramePayloadSize = 125
The max size of the ping/pong control frame payload.
Variables ¶
var ( MaxMessageSize = 1024 * 512 // the maximum size of a message CloseTimeout = 5 * time.Second )
var ( ErrPayloadOverMaxSize = errors.New("payload over maximum size") ErrPayloadTooBig = errors.New("frame payload too big") ErrWrongHandshakeRole = errors.New( "wrong role when initiating/accepting the handshake", ) ErrCannotUpgrade = errors.New( "cannot upgrade connection to WebSocket", ) ErrMessageTooBig = errors.New("message too big") ErrInvalidControlFrame = errors.New("invalid control frame") ErrControlFrameTooBig = errors.New("control frame too big") ErrSendAfterClose = errors.New("sending on a closed stream") ErrNonZeroReservedBits = errors.New("non zero reserved bits") ErrMaskedFramesFromServer = errors.New("masked frames from server") ErrUnmaskedFramesFromClient = errors.New("unmasked frames from server") ErrReservedOpcode = errors.New("reserved opcode") ErrUnexpectedContinuation = errors.New( "continue frame but nothing to continue", ) ErrExpectedContinuation = errors.New("expected continue frame") ErrInvalidAddress = errors.New("invalid address") )
var (
DialTimeout = 5 * time.Second
)
var (
ErrPartialPayload = errors.New("partial payload")
)
var GUID = []byte("258EAFA5-E914-47DA-95CA-C5AB0DC85B11")
GUID is used when constructing the Sec-WebSocket-Accept key based on Sec-WebSocket-Key.
Functions ¶
func EncodeCloseCode ¶
func EncodeCloseFramePayload ¶
func IsReserved ¶
func IsUpgradeReq ¶
IsUpgradeReq returns true if the HTTP request is a valid WebSocket upgrade.
func IsUpgradeRes ¶
IsUpgradeReq returns true if the HTTP response is a valid WebSocket upgrade.
func MakeRequestKey ¶
func MakeRequestKey() string
func MakeResponseKey ¶
func ReleaseFrame ¶
func ReleaseFrame(f *Frame)
Types ¶
type AsyncFrameHandler ¶
type AsyncMessageHandler ¶
type AsyncMessageHandler = func(err error, n int, mt MessageType)
type CloseCode ¶
type CloseCode uint16
Close status codes.
These codes accompany close frames.
const ( // CloseNormal signifies normal closure; the connection successfully // completed whatever purpose for which it was created. CloseNormal CloseCode = 1000 // GoingaAway means endpoint is going away, either because of a // server failure or because the browser is navigating away from // the page that opened the connection. CloseGoingAway CloseCode = 1001 // CloseProtocolError means the endpoint is terminating the connection // due to a protocol error. CloseProtocolError CloseCode = 1002 // CloseUnknownData means the connection is being terminated because // the endpoint received data of a type it cannot accept (for example, // a text-only endpoint received binary data). CloseUnknownData CloseCode = 1003 // CloseBadPayload means the endpoint is terminating the connection because // a message was received that contained inconsistent data // (e.g., non-UTF-8 data within a text message). CloseBadPayload CloseCode = 1007 // ClosePolicyError means the endpoint is terminating the connection because // it received a message that violates its policy. This is a generic status // code, used when codes 1003 and 1009 are not suitable. ClosePolicyError CloseCode = 1008 // CloseTooBig means the endpoint is terminating the connection because a // data frame was received that is too large. CloseTooBig CloseCode = 1009 // CloseNeedsExtension means the client is terminating the connection // because it expected the server to negotiate one or more extensions, but // the server didn't. CloseNeedsExtension CloseCode = 1010 // CloseInternalError means the server is terminating the connection because // it encountered an unexpected condition that prevented it from fulfilling // the request. CloseInternalError CloseCode = 1011 // CloseServiceRestart means the server is terminating the connection // because it is restarting. CloseServiceRestart CloseCode = 1012 // CloseTryAgainLater means the server is terminating the connection due to // a temporary condition, e.g. it is overloaded and is casting off some of // its clients. CloseTryAgainLater CloseCode = 1013 // CloseNone is used internally to mean "no error" // This code is reserved and may not be sent. CloseNone CloseCode = 0 // CloseNoStatus means no status code was provided in the close frame sent // by the peer, even though one was expected. // This code is reserved for internal use and may not be sent in-between // peers. CloseNoStatus CloseCode = 1005 // CloseAbnormal means the connection was closed without receiving a close // frame. // This code is reserved and may not be sent. CloseAbnormal CloseCode = 1006 // CloseReserved1 is reserved for future use by the WebSocket standard. // This code is reserved and may not be sent. CloseReserved1 CloseCode = 1004 // CloseReserved2 is reserved for future use by the WebSocket standard. // This code is reserved and may not be sent. CloseReserved2 CloseCode = 1014 // CloseReserved3 is reserved for future use by the WebSocket standard. // This code is reserved and may not be sent. CloseReserved3 CloseCode = 1015 )
func DecodeCloseCode ¶
func DecodeCloseFramePayload ¶
type ControlCallback ¶
type ControlCallback = func(mt MessageType, payload []byte)
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
func AcquireFrame ¶
func AcquireFrame() *Frame
func (*Frame) ExtraHeaderLen ¶
func (*Frame) IsContinuation ¶
func (*Frame) PayloadLen ¶
PayloadLen returns the actual payload length which can either be in the header if the length type is 125 or less, in the next 2 bytes if the length type is 126 or in the next 8 bytes if the length type is 127.
func (*Frame) PayloadLenType ¶
PayloadLenType returns the payload length as indicated in the fixed size header. It is always less than 127 as per the WebSocket protocol. The actual payload size can be retrieved by calling PayloadLen.
func (*Frame) SetContinuation ¶
func (f *Frame) SetContinuation()
func (*Frame) SetPayload ¶
func (*Frame) SetPayloadLen ¶
type FrameCodec ¶
type FrameCodec struct {
// contains filtered or unexported fields
}
FrameCodec is a stateful streaming parser handling the encoding and decoding of WebSocket frames.
func NewFrameCodec ¶
func NewFrameCodec(src, dst *sonic.ByteBuffer) *FrameCodec
func (*FrameCodec) Decode ¶
func (c *FrameCodec) Decode(src *sonic.ByteBuffer) (*Frame, error)
Decode decodes the raw bytes from `src` into a frame.
Three things can happen while decoding a raw stream of bytes into a frame: 1. There are not enough bytes to construct a frame with.
In this case, a nil frame and ErrNeedMore are returned. The caller should perform another read into `src` later.
2. `src` contains the bytes of one frame.
In this case we try to decode the frame. An appropriate error is returned if the frame is corrupt.
3. `src` contains the bytes of more than one frame.
In this case we try to decode the first frame. The rest of the bytes stay in `src`. An appropriate error is returned if the frame is corrupt.
func (*FrameCodec) Encode ¶
func (c *FrameCodec) Encode(fr *Frame, dst *sonic.ByteBuffer) error
Encode encodes the frame and place the raw bytes into `dst`.
type MessageType ¶
type MessageType uint8
func (MessageType) String ¶
func (t MessageType) String() string
type MockServer ¶
MockServer is a server which can be used to test the WebSocket client.
func (*MockServer) Accept ¶
func (s *MockServer) Accept(addr string) (err error)
func (*MockServer) Close ¶
func (s *MockServer) Close()
func (*MockServer) IsClosed ¶
func (s *MockServer) IsClosed() bool
func (*MockServer) Port ¶
func (s *MockServer) Port() int
func (*MockServer) Write ¶
func (s *MockServer) Write(b []byte) error
type MockStream ¶
type MockStream struct {
// contains filtered or unexported fields
}
MockStream is a mock TCP stream that's not attached to any operating system IO executor. It is used to test reads and writes for WebSocket servers and clients.
A WebsocketStream can be set to use a MockStream only if it is in StateActive, which occurs after a successful handshake or a call to init().
func NewMockStream ¶
func NewMockStream() *MockStream
func (*MockStream) AsyncClose ¶
func (s *MockStream) AsyncClose(cb func(err error))
func (*MockStream) AsyncRead ¶
func (s *MockStream) AsyncRead(b []byte, cb sonic.AsyncCallback)
func (*MockStream) AsyncReadAll ¶
func (s *MockStream) AsyncReadAll(b []byte, cb sonic.AsyncCallback)
func (*MockStream) AsyncWrite ¶
func (s *MockStream) AsyncWrite(b []byte, cb sonic.AsyncCallback)
func (*MockStream) AsyncWriteAll ¶
func (s *MockStream) AsyncWriteAll(b []byte, cb sonic.AsyncCallback)
func (*MockStream) Cancel ¶
func (s *MockStream) Cancel()
func (*MockStream) Close ¶
func (s *MockStream) Close() error
func (*MockStream) RawFd ¶
func (s *MockStream) RawFd() int
type Opcode ¶
type Opcode uint8
const ( OpcodeContinuation Opcode = 0x00 OpcodeText Opcode = 0x01 OpcodeBinary Opcode = 0x02 OpcodeRsv3 Opcode = 0x03 OpcodeRsv4 Opcode = 0x04 OpcodeRsv5 Opcode = 0x05 OpcodeRsv6 Opcode = 0x06 OpcodeRsv7 Opcode = 0x07 OpcodeClose Opcode = 0x08 OpcodePing Opcode = 0x09 OpcodePong Opcode = 0x0A OpcodeCrsvb Opcode = 0x0B OpcodeCrsvc Opcode = 0x0C OpcodeCrsvd Opcode = 0x0D OpcodeCrsve Opcode = 0x0E OpcodeCrsvf Opcode = 0x0F )
No `iota` here for clarity.
type ReasonString ¶
type ReasonString [123]byte
The type representing the reason string in a close frame.
type Stream ¶
type Stream interface { // NextLayer returns the underlying stream object. // // The returned object is constructed by the Stream and maintained // throughout its entire lifetime. All reads and writes will go through the // next layer. NextLayer() sonic.Stream // SupportsDeflate returns true if Deflate compression is supported. // // https://datatracker.ietf.org/doc/html/rfc7692 SupportsDeflate() bool // SupportsUTF8 returns true if UTF8 validity checks are supported. // // Implementations should not do UTF8 checking by default. Callers // should be able to turn it on when instantiating the Stream. SupportsUTF8() bool // NextMessage reads the payload of the next message into the supplied // buffer. Message fragmentation is automatically handled by the // implementation. // // This call first flushes any pending control frames to the underlying // stream. // // This call blocks until one of the following conditions is true: // - an error occurs while flushing the pending operations // - an error occurs when reading/decoding the message bytes from the // underlying stream // - the payload of the message is successfully read into the supplied // buffer NextMessage([]byte) (mt MessageType, n int, err error) // NextFrame reads and returns the next frame. // // This call first flushes any pending control frames to the underlying // stream. // // This call blocks until one of the following conditions is true: // - an error occurs while flushing the pending operations // - an error occurs when reading/decoding the message bytes from the // underlying stream // - a frame is successfully read from the underlying stream NextFrame() (*Frame, error) // AsyncNextMessage reads the payload of the next message into the supplied // buffer asynchronously. Message fragmentation is automatically handled by // the implementation. // // This call first flushes any pending control frames to the underlying // stream asynchronously. // // This call does not block. The provided completion handler is invoked when // one of the following happens: // - an error occurs while flushing the pending operations // - an error occurs when reading/decoding the message bytes from the // underlying stream // - the payload of the message is successfully read into the supplied // buffer AsyncNextMessage([]byte, AsyncMessageHandler) // AsyncNextFrame reads and returns the next frame asynchronously. // // This call first flushes any pending control frames to the underlying // stream asynchronously. // // This call does not block. The provided completion handler is invoked when // one of the following happens: // - an error occurs while flushing the pending operations // - an error occurs when reading/decoding the message bytes from the // underlying stream // - a frame is successfully read from the underlying stream AsyncNextFrame(AsyncFrameHandler) // WriteFrame writes the supplied frame to the underlying stream. // // This call first flushes any pending control frames to the underlying // stream. // // This call blocks until one of the following conditions is true: // - an error occurs while flushing the pending operations // - an error occurs during the write // - the frame is successfully written to the underlying stream WriteFrame(fr *Frame) error // AsyncWriteFrame writes the supplied frame to the underlying stream // asynchronously. // // This call first flushes any pending control frames to the underlying // stream asynchronously. // // This call does not block. The provided completion handler is invoked when // one of the following happens: // - an error occurs while flushing the pending operations // - an error occurs during the write // - the frame is successfully written to the underlying stream AsyncWriteFrame(fr *Frame, cb func(err error)) // Write writes the supplied buffer as a single message with the given type // to the underlying stream. // // This call first flushes any pending control frames to the underlying // stream. // // This call blocks until one of the following conditions is true: // - an error occurs while flushing the pending operations // - an error occurs during the write // - the message is successfully written to the underlying stream // // The message will be written as a single frame. Fragmentation should be // handled by the caller through multiple calls to AsyncWriteFrame. Write(b []byte, mt MessageType) error // AsyncWrite writes the supplied buffer as a single message with the given // type to the underlying stream asynchronously. // // This call first flushes any pending control frames to the underlying // stream asynchronously. // // This call does not block. The provided completion handler is invoked when // one of the following happens: // - an error occurs while flushing the pending operations // - an error occurs during the write // - the message is successfully written to the underlying stream // // The message will be written as a single frame. Fragmentation should be // handled by the caller through multiple calls to AsyncWriteFrame. AsyncWrite(b []byte, mt MessageType, cb func(err error)) // Flush writes any pending control frames to the underlying stream. // // This call blocks. Flush() error // Flush writes any pending control frames to the underlying stream // asynchronously. // // This call does not block. AsyncFlush(cb func(err error)) // Pending returns the number of currently pending operations. Pending() int // State returns the state of the WebSocket connection. State() StreamState // Handshake performs the WebSocket handshake in the client role. // // The call blocks until one of the following conditions is true: // - the request is sent and the response is received // - an error occurs Handshake(addr string, extraHeaders ...Header) error // AsyncHandshake performs the WebSocket handshake asynchronously in the // client role. // // This call does not block. The provided completion handler is called when // the request is sent and the response is received or when an error occurs. // // Regardless of whether the asynchronous operation completes immediately // or not, the handler will not be invoked from within this function. // Invocation of the handler will be performed in a manner equivalent to // using sonic.Post(...). AsyncHandshake(addr string, cb func(error), extraHeaders ...Header) // Accept performs the handshake in the server role. // // The call blocks until one of the following conditions is true: // - the request is sent and the response is received // - an error occurs Accept() error // AsyncAccept performs the handshake asynchronously in the server role. // // This call does not block. The provided completion handler is called when // the request is send and the response is received or when an error occurs. // // Regardless of whether the asynchronous operation completes immediately // or not, the handler will not be invoked from within this function. // Invocation of the handler will be performed in a manner equivalent to // using sonic.Post(...). AsyncAccept(func(error)) // AsyncClose sends a websocket close control frame asynchronously. // // This function is used to send a close frame which begins the WebSocket // closing handshake. The session ends when both ends of the connection // have sent and received a close frame. // // The handler is called if one of the following conditions is true: // - the close frame is written // - an error occurs // // After beginning the closing handshake, the program should not write // further message data, pings, or pongs. Instead, the program should // continue reading message data until an error occurs. AsyncClose(cc CloseCode, reason string, cb func(err error)) // Close sends a websocket close control frame asynchronously. // // This function is used to send a close frame which begins the WebSocket // closing handshake. The session ends when both ends of the connection // have sent and received a close frame. // // The call blocks until one of the following conditions is true: // - the close frame is written // - an error occurs // // After beginning the closing handshake, the program should not write // further message data, pings, or pongs. Instead, the program should // continue reading message data until an error occurs. Close(cc CloseCode, reason string) error // SetControlCallback sets a function that will be invoked when a // Ping/Pong/Close is received while reading a message. This callback is // not invoked when AsyncNextFrame or NextFrame are called. // // The caller must not perform any operations on the stream in the provided // callback. SetControlCallback(ControlCallback) // ControlCallback returns the control callback set with SetControlCallback. ControlCallback() ControlCallback // SetUpgradeRequestCallback sets a function that will be invoked during the handshake // just before the upgrade request is sent. // // The caller must not perform any operations on the stream in the provided callback. SetUpgradeRequestCallback(callback UpgradeRequestCallback) // UpgradeRequestCallback returns the callback set with SetUpgradeRequestCallback. UpgradeRequestCallback() UpgradeRequestCallback // SetUpgradeResponseCallback sets a function that will be invoked during the handshake // just after the upgrade response is received. // // The caller must not perform any operations on the stream in the provided callback. SetUpgradeResponseCallback(callback UpgradeResponseCallback) // UpgradeResponseCallback returns the callback set with SetUpgradeResponseCallback. UpgradeResponseCallback() UpgradeResponseCallback // SetMaxMessageSize sets the maximum size of a message that can be read // from or written to a peer. // - If a message exceeds the limit while reading, the connection is // closed abnormally. // - If a message exceeds the limit while writing, the operation is // cancelled. SetMaxMessageSize(bytes int) RemoteAddr() net.Addr LocalAddr() net.Addr RawFd() int CloseNextLayer() error }
Stream is an interface for representing a stateful WebSocket connection on the server or client side.
The interface uses the layered stream model. A WebSocket stream object contains another stream object, called the "next layer", which it uses to perform IO.
Implementations handle the replies to control frames. Before closing the stream, it is important to call Flush or AsyncFlush in order to write any pending control frame replies to the underlying stream.
type StreamState ¶
type StreamState uint8
const ( // Start state. Handshake is ongoing. StateHandshake StreamState = iota // Intermediate state. Connection is active, can read/write/close. StateActive // Intermediate state. We initiated the closing handshake and // are waiting for a reply from the peer. StateClosedByUs // Terminal state. The peer initiated the closing handshake, // we received a close frame and immediately replied. StateClosedByPeer // Terminal state. The peer replied to our closing handshake. // Can only end up here from StateClosedByUs. StateCloseAcked // Terminal state. The connection is closed or some error // occurred which rendered the stream unusable. StateTerminated )
func (StreamState) String ¶
func (s StreamState) String() string
type UpgradeRequestCallback ¶
type UpgradeResponseCallback ¶
type WebsocketStream ¶
type WebsocketStream struct {
// contains filtered or unexported fields
}
func NewWebsocketStream ¶
func (*WebsocketStream) Accept ¶
func (s *WebsocketStream) Accept() error
func (*WebsocketStream) AsyncAccept ¶
func (s *WebsocketStream) AsyncAccept(func(error))
func (*WebsocketStream) AsyncClose ¶
func (s *WebsocketStream) AsyncClose( cc CloseCode, reason string, cb func(err error), )
func (*WebsocketStream) AsyncFlush ¶
func (s *WebsocketStream) AsyncFlush(cb func(err error))
func (*WebsocketStream) AsyncHandshake ¶
func (s *WebsocketStream) AsyncHandshake( addr string, cb func(error), extraHeaders ...Header, )
func (*WebsocketStream) AsyncNextFrame ¶
func (s *WebsocketStream) AsyncNextFrame(cb AsyncFrameHandler)
func (*WebsocketStream) AsyncNextMessage ¶
func (s *WebsocketStream) AsyncNextMessage(b []byte, cb AsyncMessageHandler)
func (*WebsocketStream) AsyncWrite ¶
func (s *WebsocketStream) AsyncWrite( b []byte, mt MessageType, cb func(err error), )
func (*WebsocketStream) AsyncWriteFrame ¶
func (s *WebsocketStream) AsyncWriteFrame(f *Frame, cb func(err error))
func (*WebsocketStream) CloseNextLayer ¶
func (s *WebsocketStream) CloseNextLayer() (err error)
func (*WebsocketStream) ControlCallback ¶
func (s *WebsocketStream) ControlCallback() ControlCallback
func (*WebsocketStream) Flush ¶
func (s *WebsocketStream) Flush() (err error)
func (*WebsocketStream) Handshake ¶
func (s *WebsocketStream) Handshake( addr string, extraHeaders ...Header, ) (err error)
func (*WebsocketStream) LocalAddr ¶
func (s *WebsocketStream) LocalAddr() net.Addr
func (*WebsocketStream) NextFrame ¶
func (s *WebsocketStream) NextFrame() (f *Frame, err error)
func (*WebsocketStream) NextLayer ¶
func (s *WebsocketStream) NextLayer() sonic.Stream
func (*WebsocketStream) NextMessage ¶
func (s *WebsocketStream) NextMessage( b []byte, ) (mt MessageType, readBytes int, err error)
func (*WebsocketStream) Pending ¶
func (s *WebsocketStream) Pending() int
func (*WebsocketStream) RawFd ¶
func (s *WebsocketStream) RawFd() int
func (*WebsocketStream) RemoteAddr ¶
func (s *WebsocketStream) RemoteAddr() net.Addr
func (*WebsocketStream) SetControlCallback ¶
func (s *WebsocketStream) SetControlCallback(ccb ControlCallback)
func (*WebsocketStream) SetMaxMessageSize ¶
func (s *WebsocketStream) SetMaxMessageSize(bytes int)
func (*WebsocketStream) SetUpgradeRequestCallback ¶
func (s *WebsocketStream) SetUpgradeRequestCallback(upReqCb UpgradeRequestCallback)
func (*WebsocketStream) SetUpgradeResponseCallback ¶
func (s *WebsocketStream) SetUpgradeResponseCallback(upResCb UpgradeResponseCallback)
func (*WebsocketStream) State ¶
func (s *WebsocketStream) State() StreamState
func (*WebsocketStream) SupportsDeflate ¶
func (s *WebsocketStream) SupportsDeflate() bool
func (*WebsocketStream) SupportsUTF8 ¶
func (s *WebsocketStream) SupportsUTF8() bool
func (*WebsocketStream) UpgradeRequestCallback ¶
func (s *WebsocketStream) UpgradeRequestCallback() UpgradeRequestCallback
func (*WebsocketStream) UpgradeResponseCallback ¶
func (s *WebsocketStream) UpgradeResponseCallback() UpgradeResponseCallback
func (*WebsocketStream) Write ¶
func (s *WebsocketStream) Write(b []byte, mt MessageType) error
func (*WebsocketStream) WriteFrame ¶
func (s *WebsocketStream) WriteFrame(f *Frame) error