ws::WebSocketFramer
WebSocketFramer
#include <icy/http/websocket.h>class WebSocketFramerDefined in src/http/include/icy/http/websocket.h:156
WebSocket frame encoder/decoder and handshake validator for RFC 6455.
List of all members
| Name | Kind | Owner |
|---|---|---|
WebSocketAdapter | friend | Declared here |
wsFramerTestAccess | friend | Declared here |
wsFramerGetFlags | friend | Declared here |
WebSocketFramer | function | Declared here |
~WebSocketFramer | function | Declared here |
writeFrame | function | Declared here |
readFrame | function | Declared here |
handshakeComplete | function | Declared here |
acceptServerRequest | function | Declared here |
createClientHandshakeRequest | function | Declared here |
checkClientHandshakeResponse | function | Declared here |
completeClientHandshake | function | Declared here |
frameFlags | function | Declared here |
mustMaskPayload | function | Declared here |
mode | function | Declared here |
_mode | variable | Declared here |
_frameFlags | variable | Declared here |
_headerState | variable | Declared here |
_maskPayload | variable | Declared here |
_rnd | variable | Declared here |
_key | variable | Declared here |
_fragmented | variable | Declared here |
_fragmentOpcode | variable | Declared here |
_fragmentBuffer | variable | Declared here |
_incompleteFrame | variable | Declared here |
Friends
| Name | Description |
|---|---|
WebSocketAdapter | |
wsFramerTestAccess | |
wsFramerGetFlags |
WebSocketAdapter
friend class WebSocketAdapterDefined in src/http/include/icy/http/websocket.h:253
wsFramerTestAccess
friend void wsFramerTestAccess(WebSocketFramer & f, int state)Defined in src/http/include/icy/http/websocket.h:256
wsFramerGetFlags
friend int wsFramerGetFlags(const WebSocketFramer & f)Defined in src/http/include/icy/http/websocket.h:257
Public Methods
| Return | Name | Description |
|---|---|---|
WebSocketFramer | Creates a WebSocketFramer operating in the given endpoint mode. Client-side framers mask outgoing payloads; server-side framers do not. | |
size_t | writeFrame virtual | Encodes data into a WebSocket frame and writes it to frame. |
uint64_t | readFrame virtual | Decodes a single WebSocket frame from frame. |
bool | handshakeComplete const | Returns true if the WebSocket handshake has completed successfully. |
void | acceptServerRequest | Server side. |
void | createClientHandshakeRequest | Client side. |
bool | checkClientHandshakeResponse | Validates the server's 101 Switching Protocols response. |
void | completeClientHandshake | Completes the client-side handshake by verifying Connection, Upgrade and Sec-WebSocket-Accept headers. Advances internal state to "complete". |
WebSocketFramer
WebSocketFramer(ws::Mode mode)Defined in src/http/include/icy/http/websocket.h:162
Creates a WebSocketFramer operating in the given endpoint mode. Client-side framers mask outgoing payloads; server-side framers do not.
Parameters
modeServerSide or ClientSide.
writeFrame
virtual
virtual size_t writeFrame(const char * data, size_t len, int flags, BitWriter & frame)Defined in src/http/include/icy/http/websocket.h:173
Encodes data into a WebSocket frame and writes it to frame.
Parameters
dataPointer to the payload data.lenPayload length in bytes.flagsFrame flags: ws::SendFlags::Text, ws::SendFlags::Binary, or a control frame opcode combined with FrameFlags::Fin.frameBitWriter to write the encoded frame into.
Returns
Total number of bytes written to the frame buffer (header + payload).
readFrame
virtual
virtual uint64_t readFrame(BitReader & frame, char *& payload)Defined in src/http/include/icy/http/websocket.h:184
Decodes a single WebSocket frame from frame.
The payload is unmasked in-place in the source buffer; no copy is made. payload is set to point at the start of the payload within frame's buffer.
Parameters
frameBitReader positioned at the start of a frame.payloadSet to point at the start of the decoded payload. Not null-terminated.
Returns
Payload length in bytes.
Exceptions
std::runtime_erroron protocol violations or if the buffer is too small.
handshakeComplete
const
bool handshakeComplete() constDefined in src/http/include/icy/http/websocket.h:187
Returns true if the WebSocket handshake has completed successfully.
acceptServerRequest
void acceptServerRequest(http::Request & request, http::Response & response)Defined in src/http/include/icy/http/websocket.h:197
Server side.
Validates the client upgrade request and writes a 101 Switching Protocols response. Sets the internal state to mark the handshake as complete.
Parameters
requestIncoming HTTP upgrade request.responseHTTP response to populate with the handshake reply.
Exceptions
std::runtime_errorif the request is not a valid WebSocket upgrade.
createClientHandshakeRequest
void createClientHandshakeRequest(http::Request & request)Defined in src/http/include/icy/http/websocket.h:205
Client side.
Populates request with the WebSocket upgrade headers (Connection, Upgrade, Sec-WebSocket-Key, Sec-WebSocket-Version) to initiate the handshake.
Parameters
requestHTTP request to add upgrade headers to.
checkClientHandshakeResponse
bool checkClientHandshakeResponse(http::Response & response)Defined in src/http/include/icy/http/websocket.h:211
Validates the server's 101 Switching Protocols response.
Parameters
responseThe HTTP response received from the server.
Returns
true if the handshake succeeded and data can flow.
Exceptions
std::runtime_errorif the server rejected or mishandled the upgrade.
completeClientHandshake
void completeClientHandshake(http::Response & response)Defined in src/http/include/icy/http/websocket.h:217
Completes the client-side handshake by verifying Connection, Upgrade and Sec-WebSocket-Accept headers. Advances internal state to "complete".
Parameters
responseThe 101 Switching Protocols response from the server.
Exceptions
std::runtime_errorif any required header is missing or incorrect.
Protected Methods
| Return | Name | Description |
|---|---|---|
int | frameFlags const | Returns the frame flags of the most recently received frame. Set by readFrame() |
bool | mustMaskPayload const | Returns true if the payload must be masked. Used by writeFrame() |
ws::Mode | mode const |
frameFlags
const
int frameFlags() constDefined in src/http/include/icy/http/websocket.h:222
Returns the frame flags of the most recently received frame. Set by readFrame()
mustMaskPayload
const
bool mustMaskPayload() constDefined in src/http/include/icy/http/websocket.h:226
Returns true if the payload must be masked. Used by writeFrame()
mode
const
ws::Mode mode() constDefined in src/http/include/icy/http/websocket.h:228
Private Attributes
| Return | Name | Description |
|---|---|---|
ws::Mode | _mode | |
int | _frameFlags | |
int | _headerState | |
bool | _maskPayload | |
Random | _rnd | |
std::string | _key | |
bool | _fragmented | Currently receiving a fragmented message. |
int | _fragmentOpcode | Opcode of the first frame in the fragment sequence. |
Buffer | _fragmentBuffer | Accumulated payload from continuation frames. |
Buffer | _incompleteFrame | Buffer for incomplete frame data across TCP segments. |
_mode
ws::Mode _modeDefined in src/http/include/icy/http/websocket.h:238
_frameFlags
int _frameFlagsDefined in src/http/include/icy/http/websocket.h:239
_headerState
int _headerStateDefined in src/http/include/icy/http/websocket.h:240
_maskPayload
bool _maskPayloadDefined in src/http/include/icy/http/websocket.h:241
_rnd
Random _rndDefined in src/http/include/icy/http/websocket.h:242
_key
std::string _keyDefined in src/http/include/icy/http/websocket.h:243
_fragmented
bool _fragmented {false}Defined in src/http/include/icy/http/websocket.h:246
Currently receiving a fragmented message.
_fragmentOpcode
int _fragmentOpcode {0}Defined in src/http/include/icy/http/websocket.h:247
Opcode of the first frame in the fragment sequence.
_fragmentBuffer
Buffer _fragmentBufferDefined in src/http/include/icy/http/websocket.h:248
Accumulated payload from continuation frames.
_incompleteFrame
Buffer _incompleteFrameDefined in src/http/include/icy/http/websocket.h:251
Buffer for incomplete frame data across TCP segments.
