ws::WebSocketAdapter
WebSocketAdapter
#include <websocket.h>
class WebSocketAdapterDefined in src/http/include/icy/http/websocket.h:267
- Inherits
SocketEmitter- Subclassed by
ConnectionAdapter,WebSocket
Friends
| Name | Description |
|---|---|
WebSocketFramer |
WebSocketFramer
friend class WebSocketFramerDefined in src/http/include/icy/http/websocket.h:350
Public Attributes
| Return | Name | Description |
|---|---|---|
net::Socket::Ptr | socket | Pointer to the underlying socket. Sent data will be proxied to this socket. |
socket
net::Socket::Ptr socketDefined in src/http/include/icy/http/websocket.h:304
Pointer to the underlying socket. Sent data will be proxied to this socket.
Public Methods
| Return | Name | Description |
|---|---|---|
WebSocketAdapter | Creates a WebSocketAdapter using the given socket, mode and HTTP message objects. | |
ssize_t | send virtual override | Frames and sends data to the peer's address. |
ssize_t | send virtual override | Frames and sends data to a specific peer address (for UDP-backed sockets). |
ssize_t | sendOwned virtual override | |
ssize_t | sendOwned virtual override | |
bool | shutdown virtual | Sends a WebSocket CLOSE frame with the given status code and message, then closes the underlying socket. |
void | sendClientRequest virtual | Client side. |
void | handleClientResponse virtual | Parses the server's HTTP upgrade response and completes the handshake. Any data remaining in the buffer after the HTTP response is re-fed as WebSocket frames. |
void | handleServerRequest virtual | Server side. |
void | onHandshakeComplete virtual | Called when the WebSocket handshake completes. Emits the connect event to downstream handlers. |
WebSocketAdapter
WebSocketAdapter(const net::Socket::Ptr & socket, ws::Mode mode, http::Request & request, http::Response & response)Defined in src/http/include/icy/http/websocket.h:275
Creates a WebSocketAdapter using the given socket, mode and HTTP message objects.
Parameters
| Parameter | Type | Description |
|---|---|---|
socket | const net::Socket::Ptr & | The underlying TCP or SSL socket. |
mode | ws::Mode | ServerSide or ClientSide. |
request | http::Request & | HTTP request used for the handshake. |
response | http::Response & | HTTP response used for the handshake. |
send
virtual override
virtual ssize_t send(const char * data, size_t len, int flags = 0) overrideDefined in src/http/include/icy/http/websocket.h:283
Frames and sends data to the peer's address.
Returns
Number of bytes sent, or -1 on error.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | const char * | Pointer to the payload. |
len | size_t | Payload length in bytes. |
flags | int | ws::SendFlags::Text or ws::SendFlags::Binary. |
send
virtual override
virtual ssize_t send(const char * data, size_t len, const net::Address & peerAddr, int flags = 0) overrideDefined in src/http/include/icy/http/websocket.h:291
Frames and sends data to a specific peer address (for UDP-backed sockets).
Returns
Number of bytes sent, or -1 on error.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | const char * | Pointer to the payload. |
len | size_t | Payload length in bytes. |
peerAddr | const net::Address & | Destination address. |
flags | int | ws::SendFlags::Text or ws::SendFlags::Binary. |
sendOwned
virtual override
virtual ssize_t sendOwned(Buffer && buffer, int flags = 0) overrideDefined in src/http/include/icy/http/websocket.h:292
sendOwned
virtual override
virtual ssize_t sendOwned(Buffer && buffer, const net::Address & peerAddr, int flags = 0) overrideDefined in src/http/include/icy/http/websocket.h:293
shutdown
virtual
virtual bool shutdown(uint16_t statusCode, const std::string & statusMessage)Defined in src/http/include/icy/http/websocket.h:300
Sends a WebSocket CLOSE frame with the given status code and message, then closes the underlying socket.
Returns
true if the close frame was sent successfully.
Parameters
| Parameter | Type | Description |
|---|---|---|
statusCode | uint16_t | WebSocket close status code (e.g. 1000 for normal close). |
statusMessage | const std::string & | Human-readable reason for closing. |
sendClientRequest
virtual
virtual void sendClientRequest()Defined in src/http/include/icy/http/websocket.h:311
Client side.
Sends the WebSocket HTTP upgrade request to initiate the handshake. Called automatically on socket connect.
handleClientResponse
virtual
virtual void handleClientResponse(const MutableBuffer & buffer, const net::Address & peerAddr)Defined in src/http/include/icy/http/websocket.h:317
Parses the server's HTTP upgrade response and completes the handshake. Any data remaining in the buffer after the HTTP response is re-fed as WebSocket frames.
Parameters
| Parameter | Type | Description |
|---|---|---|
buffer | const MutableBuffer & | Buffer containing the server's HTTP response. |
peerAddr | const net::Address & | Address of the peer. |
handleServerRequest
virtual
virtual void handleServerRequest(const MutableBuffer & buffer, const net::Address & peerAddr)Defined in src/http/include/icy/http/websocket.h:325
Server side.
Parses the client's HTTP upgrade request and sends the 101 response.
Parameters
| Parameter | Type | Description |
|---|---|---|
buffer | const MutableBuffer & | Buffer containing the client's HTTP upgrade request. |
peerAddr | const net::Address & | Address of the peer. |
onHandshakeComplete
virtual
virtual void onHandshakeComplete()Defined in src/http/include/icy/http/websocket.h:339
Called when the WebSocket handshake completes. Emits the connect event to downstream handlers.
Reimplemented by
Protected Attributes
| Return | Name | Description |
|---|---|---|
WebSocketFramer | framer | |
http::Request & | _request | |
http::Response & | _response | |
ws::CloseState | _closeState |
framer
WebSocketFramer framerType: WebSocketFramer
Defined in src/http/include/icy/http/websocket.h:352
_request
http::Request & _requestDefined in src/http/include/icy/http/websocket.h:353
_response
http::Response & _responseDefined in src/http/include/icy/http/websocket.h:354
_closeState
ws::CloseState _closeState {ws::CloseState::Open}Type: ws::CloseState
Defined in src/http/include/icy/http/websocket.h:355
Protected Methods
| Return | Name | Description |
|---|---|---|
~WebSocketAdapter virtual | ||
bool | sendControlFrame | |
void | resetFrameState |
~WebSocketAdapter
virtual
virtual ~WebSocketAdapter()Defined in src/http/include/icy/http/websocket.h:342
sendControlFrame
bool sendControlFrame(ws::Opcode opcode, const char * payload, size_t payloadLen, const net::Address & peerAddr)Defined in src/http/include/icy/http/websocket.h:344
resetFrameState
void resetFrameState()Defined in src/http/include/icy/http/websocket.h:348
Private Methods
| Return | Name | Description |
|---|---|---|
bool | onSocketConnect virtual override | Called by the socket on connect; initiates the client handshake. |
bool | onSocketRecv virtual override | Called by the socket on each received buffer; handles handshake or frame parsing depending on state. |
bool | onSocketClose virtual override | Called by the socket on close; resets framer state. |
onSocketConnect
virtual override
virtual bool onSocketConnect(net::Socket & socket) overrideDefined in src/http/include/icy/http/websocket.h:328
Called by the socket on connect; initiates the client handshake.
onSocketRecv
virtual override
virtual bool onSocketRecv(net::Socket & socket, const MutableBuffer & buffer, const net::Address & peerAddress) overrideDefined in src/http/include/icy/http/websocket.h:332
Called by the socket on each received buffer; handles handshake or frame parsing depending on state.
onSocketClose
virtual override
virtual bool onSocketClose(net::Socket & socket) overrideDefined in src/http/include/icy/http/websocket.h:335
Called by the socket on close; resets framer state.