ws::WebSocketAdapter
WebSocketAdapter
#include <icy/http/websocket.h>class WebSocketAdapterDefined in src/http/include/icy/http/websocket.h:267
Inherits:
SocketEmitterSubclassed by:ConnectionAdapter,WebSocket
WebSocket protocol adapter for both client and server endpoints.
List of all members
| Name | Kind | Owner |
|---|---|---|
WebSocketFramer | friend | Declared here |
socket | variable | Declared here |
WebSocketAdapter | function | Declared here |
send | function | Declared here |
send | function | Declared here |
sendOwned | function | Declared here |
sendOwned | function | Declared here |
shutdown | function | Declared here |
sendClientRequest | function | Declared here |
handleClientResponse | function | Declared here |
handleServerRequest | function | Declared here |
onHandshakeComplete | function | Declared here |
framer | variable | Declared here |
_request | variable | Declared here |
_response | variable | Declared here |
_closeState | variable | Declared here |
~WebSocketAdapter | function | Declared here |
sendControlFrame | function | Declared here |
resetFrameState | function | Declared here |
onSocketConnect | function | Declared here |
onSocketRecv | function | Declared here |
onSocketClose | function | Declared here |
Connect | variable | Inherited from SocketEmitter |
Recv | variable | Inherited from SocketEmitter |
Error | variable | Inherited from SocketEmitter |
Close | variable | Inherited from SocketEmitter |
impl | variable | Inherited from SocketEmitter |
SocketEmitter | function | Inherited from SocketEmitter |
SocketEmitter | function | Inherited from SocketEmitter |
~SocketEmitter | function | Inherited from SocketEmitter |
addReceiver | function | Inherited from SocketEmitter |
removeReceiver | function | Inherited from SocketEmitter |
swap | function | Inherited from SocketEmitter |
as | function | Inherited from SocketEmitter |
operator-> | function | Inherited from SocketEmitter |
onSocketConnect | function | Inherited from SocketEmitter |
onSocketRecv | function | Inherited from SocketEmitter |
onSocketError | function | Inherited from SocketEmitter |
onSocketClose | function | Inherited from SocketEmitter |
priority | variable | Inherited from SocketAdapter |
SocketAdapter | function | Inherited from SocketAdapter |
~SocketAdapter | function | Inherited from SocketAdapter |
send | function | Inherited from SocketAdapter |
send | function | Inherited from SocketAdapter |
sendOwned | function | Inherited from SocketAdapter |
sendOwned | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
setSender | function | Inherited from SocketAdapter |
sender | function | Inherited from SocketAdapter |
addReceiver | function | Inherited from SocketAdapter |
removeReceiver | function | Inherited from SocketAdapter |
hasReceiver | function | Inherited from SocketAdapter |
receivers | function | Inherited from SocketAdapter |
onSocketConnect | function | Inherited from SocketAdapter |
onSocketRecv | function | Inherited from SocketAdapter |
onSocketError | function | Inherited from SocketAdapter |
onSocketClose | function | Inherited from SocketAdapter |
_sender | variable | Inherited from SocketAdapter |
_receivers | variable | Inherited from SocketAdapter |
_dirty | variable | Inherited from SocketAdapter |
cleanupReceivers | function | Inherited from SocketAdapter |
Inherited from SocketEmitter
| Kind | Name | Description |
|---|---|---|
variable | Connect | Signals that the socket is connected. |
variable | Recv | Signals when data is received by the socket. |
variable | Error | Signals that the socket is closed in error. This signal will be sent just before the Closed signal. |
variable | Close | Signals that the underlying socket is closed. |
variable | impl | Pointer to the underlying socket. Sent data will be proxied to this socket. |
function | SocketEmitter | Creates the SocketEmitter and optionally attaches it to a socket. If socket is provided, this emitter registers itself as a receiver. |
function | SocketEmitter | Copy constructor; copies all signal connections and attaches to the same socket. |
function | ~SocketEmitter virtual noexcept | Destroys the SocketAdapter. |
function | addReceiver virtual override | Attaches a SocketAdapter as a receiver; wires it to all four socket signals. |
function | removeReceiver virtual override | Detaches a SocketAdapter from all four socket signals. |
function | swap virtual | Replaces the underlying socket with socket. |
function | as inline | Returns the underlying socket cast to type T, or nullptr if the cast fails. |
function | operator-> const inline | Returns a raw pointer to the underlying socket for direct method access. Follows shared_ptr semantics; the caller must not delete the returned pointer. |
function | onSocketConnect virtual override | Forwards the connect event to chained adapters, then fires the Connect signal. |
function | onSocketRecv virtual override | Forwards the recv event to chained adapters, then fires the Recv signal. |
function | onSocketError virtual override | Forwards the error event to chained adapters, then fires the Error signal. |
function | onSocketClose virtual override | Forwards the close event to chained adapters, then fires the Close signal. |
Inherited from SocketAdapter
| Kind | Name | Description |
|---|---|---|
variable | priority | The priority of this adapter for STL sort operations. |
function | SocketAdapter | Creates the SocketAdapter. |
function | ~SocketAdapter virtual noexcept | Destroys the SocketAdapter. |
function | send virtual | Sends the given data buffer to the connected peer. Returns the number of bytes sent or -1 on error. No exception will be thrown. For TCP sockets the given peer address must match the connected peer address. |
function | send virtual | |
function | sendOwned virtual | Sends an owned payload buffer to the connected peer. |
function | sendOwned virtual | |
function | sendPacket virtual | Sends the given packet to the connected peer. Returns the number of bytes sent or -1 on error. No exception will be thrown. For TCP sockets the given peer address must match the connected peer address. |
function | sendPacket virtual | |
function | sendPacket virtual | Sends the given packet to the connected peer. This method provides delegate compatibility, and unlike other send methods throws an exception if the underlying socket is closed. |
function | setSender virtual | Sets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default. |
function | sender | Returns the output SocketAdapter pointer. |
function | addReceiver virtual | Sets the pointer to the incoming data adapter. Events proxy data to this adapter by default. |
function | removeReceiver virtual | Remove the given receiver. |
function | hasReceiver virtual | Returns true if the given receiver is connected. |
function | receivers | Returns all currently registered input SocketAdapter pointers. Dead (removed) entries are excluded from the returned list. |
function | onSocketConnect virtual | Called when the socket establishes a connection. Forwards the event to all registered receivers in priority order. Override to intercept before the application sees the event. |
function | onSocketRecv virtual | Called when data is received from the socket. Forwards the event to all registered receivers in priority order. |
function | onSocketError virtual | Called when the socket encounters an error. Forwards the event to all registered receivers in priority order. |
function | onSocketClose virtual | Called when the socket is closed. Forwards the event to all registered receivers in priority order. |
variable | _sender | |
variable | _receivers | |
variable | _dirty | |
function | cleanupReceivers virtual |
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 | Sends an owned payload buffer to the connected peer. |
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
socketThe underlying TCP or SSL socket.modeServerSide or ClientSide.requestHTTP request used for the handshake.responseHTTP 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.
Parameters
dataPointer to the payload.lenPayload length in bytes.flagsws::SendFlags::Text or ws::SendFlags::Binary.
Returns
Number of bytes sent, or -1 on error.
Reimplements
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).
Parameters
dataPointer to the payload.lenPayload length in bytes.peerAddrDestination address.flagsws::SendFlags::Text or ws::SendFlags::Binary.
Returns
Number of bytes sent, or -1 on error.
Reimplements
sendOwned
virtual override
virtual ssize_t sendOwned(Buffer && buffer, int flags = 0) overrideDefined in src/http/include/icy/http/websocket.h:292
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.
Reimplements
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
Reimplements
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.
Parameters
statusCodeWebSocket close status code (e.g. 1000 for normal close).statusMessageHuman-readable reason for closing.
Returns
true if the close frame was sent successfully.
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
bufferBuffer containing the server's HTTP response.peerAddrAddress 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
bufferBuffer containing the client's HTTP upgrade request.peerAddrAddress 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 framerDefined 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 {}Defined in src/http/include/icy/http/websocket.h:355
Protected Methods
| Return | Name | Description |
|---|---|---|
bool | sendControlFrame | |
void | resetFrameState |
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.
Reimplements
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.
Reimplements
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.
