CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
cmlabs::HTTPProtocol Class Reference

Server-side HTTP/WebSocket protocol handler (static send/receive helpers). More...

#include <NetworkProtocols.h>

Inheritance diagram for cmlabs::HTTPProtocol:
[legend]
Collaboration diagram for cmlabs::HTTPProtocol:
[legend]

Public Member Functions

 HTTPProtocol ()
Public Member Functions inherited from cmlabs::NetworkProtocol
 NetworkProtocol ()

Static Public Member Functions

static bool CheckBufferForCompatibility (const char *buffer, uint32 length)
static bool InitialiseConversation (NetworkConnection *con)
 No initial exchange needed for HTTP.
static bool SendHTTPReply (NetworkConnection *con, HTTPReply *reply)
 Serialise and send a reply.
static HTTPReplyReceiveHTTPReply (NetworkConnection *con, uint32 timeout)
 Read a full reply from the connection.
static bool SendHTTPRequest (NetworkConnection *con, HTTPRequest *req)
 Serialise and send a request.
static HTTPRequestReceiveHTTPRequest (NetworkConnection *con, uint32 timeout)
 Read a full request from the connection.
static WebsocketDataReceiveWebsocketData (NetworkConnection *con, uint32 timeout)
 Read one complete WebSocket message (reassembling fragments).
static bool SendWebsocketData (NetworkConnection *con, WebsocketData *wsData)
 Send a WebSocket frame.
Static Public Member Functions inherited from cmlabs::NetworkProtocol
static bool CheckBufferForCompatibility (const char *buffer, uint32 length)
 Sniff whether buffer looks like this protocol.
static bool InitialiseConversation (NetworkConnection *con)
 Perform any protocol-specific initial exchange on a new connection.

Additional Inherited Members

Public Attributes inherited from cmlabs::NetworkProtocol
uint8 protocol
 PROTOCOL_* id of this handler.

Detailed Description

Server-side HTTP/WebSocket protocol handler (static send/receive helpers).

Reads HTTPRequests and WebSocket frames from a connection and writes HTTPReplies / frames back, with millisecond timeouts. Used by NetworkChannel::HTTPServerRun() — the built-in HTTP server thread.

Definition at line 819 of file NetworkProtocols.h.

Constructor & Destructor Documentation

◆ HTTPProtocol()

cmlabs::HTTPProtocol::HTTPProtocol ( )
inline

Definition at line 822 of file NetworkProtocols.h.

References cmlabs::NetworkProtocol::protocol, and PROTOCOL_HTTP_SERVER.

Member Function Documentation

◆ CheckBufferForCompatibility()

bool cmlabs::HTTPProtocol::CheckBufferForCompatibility ( const char * buffer,
uint32 length )
static
Returns
true when buffer starts like an HTTP request (method line).

Definition at line 1851 of file NetworkProtocols.cpp.

References cmlabs::utils::stristr().

Referenced by cmlabs::NetworkChannel::ConnectionAutodetectRun().

◆ InitialiseConversation()

bool cmlabs::HTTPProtocol::InitialiseConversation ( NetworkConnection * con)
static

No initial exchange needed for HTTP.

Parameters
conConnection.
Returns
true.

Definition at line 1862 of file NetworkProtocols.cpp.

◆ ReceiveHTTPReply()

◆ ReceiveHTTPRequest()

◆ ReceiveWebsocketData()

◆ SendHTTPReply()

bool cmlabs::HTTPProtocol::SendHTTPReply ( NetworkConnection * con,
HTTPReply * reply )
static

Serialise and send a reply.

Parameters
conConnection.
replyReply (caller keeps ownership).
Returns
true if fully sent.

Definition at line 1866 of file NetworkProtocols.cpp.

References cmlabs::HTTPReply::data, cmlabs::HTTPReply::getSize(), LOG_NETWORK, LogPrint, and cmlabs::NetworkConnection::send().

Referenced by cmlabs::NetworkChannel::sendHTTPReply().

◆ SendHTTPRequest()

bool cmlabs::HTTPProtocol::SendHTTPRequest ( NetworkConnection * con,
HTTPRequest * req )
static

Serialise and send a request.

Parameters
conConnection.
reqRequest (caller keeps ownership).
Returns
true if fully sent.

Definition at line 2033 of file NetworkProtocols.cpp.

References cmlabs::HTTPRequest::data, cmlabs::HTTPRequest::getSize(), and cmlabs::NetworkConnection::send().

Referenced by cmlabs::NetworkChannel::createWebsocketConnection(), cmlabs::LLMConnection::interactStream(), cmlabs::NetworkChannel::sendHTTPRequest(), and cmlabs::NetworkChannel::sendReceiveHTTPRequest().

◆ SendWebsocketData()

bool cmlabs::HTTPProtocol::SendWebsocketData ( NetworkConnection * con,
WebsocketData * wsData )
static

Send a WebSocket frame.

Parameters
conConnection.
wsDataFrame (caller keeps ownership).
Returns
true if fully sent.

Definition at line 2250 of file NetworkProtocols.cpp.

References cmlabs::WebsocketData::getRawData(), and cmlabs::NetworkConnection::send().

Referenced by cmlabs::NetworkChannel::sendWebsocketData().


The documentation for this class was generated from the following files: