|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
Server-side HTTP/WebSocket protocol handler (static send/receive helpers). More...
#include <NetworkProtocols.h>
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 HTTPReply * | ReceiveHTTPReply (NetworkConnection *con, uint32 timeout) |
| Read a full reply from the connection. | |
| static bool | SendHTTPRequest (NetworkConnection *con, HTTPRequest *req) |
| Serialise and send a request. | |
| static HTTPRequest * | ReceiveHTTPRequest (NetworkConnection *con, uint32 timeout) |
| Read a full request from the connection. | |
| static WebsocketData * | ReceiveWebsocketData (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. | |
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.
|
inline |
Definition at line 822 of file NetworkProtocols.h.
References cmlabs::NetworkProtocol::protocol, and PROTOCOL_HTTP_SERVER.
|
static |
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().
|
static |
No initial exchange needed for HTTP.
| con | Connection. |
Definition at line 1862 of file NetworkProtocols.cpp.
|
static |
Read a full reply from the connection.
| con | Connection. |
| timeout | Max wait in ms. |
Definition at line 1883 of file NetworkProtocols.cpp.
References cmlabs::HTTPReply::chunked, cmlabs::HTTPReply::contentLength, cmlabs::HTTPReply::CreateErrorReply(), cmlabs::NetworkConnection::discard(), cmlabs::NetworkConnection::getRemoteAddress(), cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), cmlabs::HTTPReply::headerLength, HTTP_SERVER_MALFORMED_REPLY, HTTP_SERVER_NOREPLY, cmlabs::HTTPReply::processContent(), cmlabs::HTTPReply::processHeader(), cmlabs::NetworkConnection::receive(), cmlabs::NetworkConnection::receiveAvailable(), cmlabs::HTTPReply::setDecodedContent(), and cmlabs::NetworkConnection::waitForDataToRead().
Referenced by cmlabs::NetworkChannel::HTTPClientRun().
|
static |
Read a full request from the connection.
| con | Connection. |
| timeout | Max wait in ms. |
Definition at line 2039 of file NetworkProtocols.cpp.
References cmlabs::HTTPRequest::contentLength, cmlabs::NetworkConnection::discard(), cmlabs::NetworkConnection::getRemoteAddress(), cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), cmlabs::HTTPRequest::headerLength, LOG_NETWORK, LogPrint, cmlabs::HTTPRequest::processContent(), cmlabs::HTTPRequest::processHeader(), cmlabs::NetworkConnection::receive(), cmlabs::NetworkConnection::receiveAvailable(), cmlabs::utils::Sleep(), and cmlabs::NetworkConnection::waitForDataToRead().
Referenced by cmlabs::NetworkChannel::HTTPServerRun().
|
static |
Read one complete WebSocket message (reassembling fragments).
| con | Connection. |
| timeout | Max wait in ms. |
Definition at line 2139 of file NetworkProtocols.cpp.
References cmlabs::NetworkConnection::discard(), GETIPADDRESSQUAD, cmlabs::NetworkConnection::getRemoteAddress(), cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), cmlabs::WebsocketData::headerLength, cmlabs::WebsocketData::isComplete(), LOG_NETWORK, LogPrint, cmlabs::WebsocketData::payloadSize, cmlabs::WebsocketData::processContent(), cmlabs::WebsocketData::processHeader(), cmlabs::NetworkConnection::receive(), cmlabs::NetworkConnection::receiveAvailable(), cmlabs::utils::Sleep(), and cmlabs::NetworkConnection::waitForDataToRead().
Referenced by cmlabs::NetworkChannel::HTTPClientRun(), and cmlabs::NetworkChannel::HTTPServerRun().
|
static |
Serialise and send a reply.
| con | Connection. |
| reply | Reply (caller keeps ownership). |
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().
|
static |
Serialise and send a request.
| con | Connection. |
| req | Request (caller keeps ownership). |
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().
|
static |
Send a WebSocket frame.
| con | Connection. |
| wsData | Frame (caller keeps ownership). |
Definition at line 2250 of file NetworkProtocols.cpp.
References cmlabs::WebsocketData::getRawData(), and cmlabs::NetworkConnection::send().
Referenced by cmlabs::NetworkChannel::sendWebsocketData().