#include <icy/http/websocket.h>Inherits:
SocketEmitterSubclassed by:ConnectionAdapter,WebSocket
WebSocket protocol adapter for both client and server endpoints.
| Return | Name | Description |
|---|---|---|
net::Socket::Ptr | socket | Pointer to the underlying socket. Sent data will be proxied to this socket. |
net::Socket::Ptr socketPointer to the underlying socket. Sent data will be proxied to this socket.
| Return | Name | Description |
|---|---|---|
WebSocketAdapter | Creates a WebSocketAdapter using the given socket, mode and HTTP message objects. | |
ssize_t | send virtual | Frames and sends data to the peer's address. |
ssize_t | send virtual | Frames and sends data to a specific peer address (for UDP-backed sockets). |
ssize_t | sendOwned virtual | Sends an owned payload buffer to the connected peer. |
ssize_t | sendOwned virtual | |
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(const net::Socket::Ptr & socket, ws::Mode mode, http::Request & request, http::Response & response)Creates a WebSocketAdapter using the given socket, mode and HTTP message objects.
socket The underlying TCP or SSL socket.
mode ServerSide or ClientSide.
request HTTP request used for the handshake.
response HTTP response used for the handshake.
virtual
virtual ssize_t send(const char * data, size_t len, int flags)Frames and sends data to the peer's address.
data Pointer to the payload.
len Payload length in bytes.
flags ws::SendFlags::Text or ws::SendFlags::Binary.
Number of bytes sent, or -1 on error.
virtual
virtual ssize_t send(const char * data, size_t len, const net::Address & peerAddr, int flags)Frames and sends data to a specific peer address (for UDP-backed sockets).
data Pointer to the payload.
len Payload length in bytes.
peerAddr Destination address.
flags ws::SendFlags::Text or ws::SendFlags::Binary.
Number of bytes sent, or -1 on error.
virtual
virtual ssize_t sendOwned(Buffer && buffer, int flags)Sends an owned payload buffer to the connected peer.
The buffer is moved through the adapter chain and retained by the transport layer until async write completion.
virtual
virtual ssize_t sendOwned(Buffer && buffer, const net::Address & peerAddr, int flags)virtual
virtual bool shutdown(uint16_t statusCode, const std::string & statusMessage)Sends a WebSocket CLOSE frame with the given status code and message, then closes the underlying socket.
statusCode WebSocket close status code (e.g. 1000 for normal close).
statusMessage Human-readable reason for closing.
true if the close frame was sent successfully.
virtual
virtual void sendClientRequest()Client side.
Sends the WebSocket HTTP upgrade request to initiate the handshake. Called automatically on socket connect.
virtual
virtual void handleClientResponse(const MutableBuffer & buffer, const net::Address & peerAddr)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.
buffer Buffer containing the server's HTTP response.
peerAddr Address of the peer.
virtual
virtual void handleServerRequest(const MutableBuffer & buffer, const net::Address & peerAddr)Server side.
Parses the client's HTTP upgrade request and sends the 101 response.
buffer Buffer containing the client's HTTP upgrade request.
peerAddr Address of the peer.
virtual
virtual void onHandshakeComplete()Called when the WebSocket handshake completes. Emits the connect event to downstream handlers.
| Return | Name | Description |
|---|---|---|
WebSocketFramer | framer | |
http::Request & | _request | |
http::Response & | _response | |
ws::CloseState | _closeState |
WebSocketFramer framerhttp::Request & _requesthttp::Response & _responsews::CloseState _closeState {}| Return | Name | Description |
|---|---|---|
bool | sendControlFrame | |
void | resetFrameState |
bool sendControlFrame(ws::Opcode opcode, const char * payload, size_t payloadLen, const net::Address & peerAddr)void resetFrameState()| Return | Name | Description |
|---|---|---|
bool | onSocketConnect virtual | Called by the socket on connect; initiates the client handshake. |
bool | onSocketRecv virtual | Called by the socket on each received buffer; handles handshake or frame parsing depending on state. |
bool | onSocketClose virtual | Called by the socket on close; resets framer state. |
virtual
virtual bool onSocketConnect(net::Socket & socket)Called by the socket on connect; initiates the client handshake.
virtual
virtual bool onSocketRecv(net::Socket & socket, const MutableBuffer & buffer, const net::Address & peerAddress)Called by the socket on each received buffer; handles handshake or frame parsing depending on state.
virtual
virtual bool onSocketClose(net::Socket & socket)Called by the socket on close; resets framer state.