|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
One logical network interface: a group of listeners/connections with shared dispatch. More...
#include <NetworkManager.h>
Public Member Functions | |
| NetworkChannel (NetworkManager *manager) | |
| virtual | ~NetworkChannel () |
| bool | isConnected (uint64 conid) |
| bool | shutdown () |
| Stop all worker threads and close all listeners/connections of this channel. | |
| bool | startListener (uint64 cid, uint16 port, uint8 encryption, uint8 protocol, bool isAsync, uint32 protocolTimeout=3000, bool isDefaultProtocol=false) |
| Open a listener on this channel (see NetworkManager::createListener() for semantics). | |
| bool | stopListener (uint16 port, uint8 protocol) |
| Stop a listener on this channel. | |
| uint64 | createTCPConnection (const char *addr, uint16 port, uint8 encryption, uint8 protocol, bool isAsync, bool autoreconnect, uint64 &location, uint32 timeoutMS=5000) |
| Connect to a host by name/IP; see NetworkManager::createTCPConnection(). | |
| uint64 | createTCPConnection (uint64 location, uint8 encryption, uint8 protocol, bool isAsync, bool autoreconnect, uint32 timeoutMS=5000) |
| Connect to a packed uint64 endpoint. | |
| uint64 | createTCPConnection (const uint32 *addresses, uint16 addressCount, uint16 port, uint8 encryption, uint8 protocol, bool isAsync, bool autoreconnect, uint64 &location, uint32 timeoutMS=5000) |
| Connect trying several candidate addresses. | |
| uint64 | createUDPConnection (uint16 port, uint8 protocol, bool isAsync, bool autoreconnect) |
| Bind a UDP port on this channel. | |
| uint64 | addTCPConnection (const char *addr, uint16 port, uint8 encryption, uint8 protocol, bool isAsync, uint64 &location, uint32 timeoutMS=5000, const char *greetingData=NULL, uint32 greetingSize=0) |
| Connect with optional greeting bytes (no autoreconnect); see NetworkManager::addTCPConnection(). | |
| uint64 | addTCPConnection (uint64 location, uint8 encryption, uint8 protocol, bool isAsync, uint32 timeoutMS=5000, const char *greetingData=NULL, uint32 greetingSize=0) |
| Packed-endpoint variant of addTCPConnection(). | |
| uint64 | createWebsocketConnection (const char *url, const char *protocolName, const char *origin=NULL, uint32 timeoutMS=5000) |
| Open a client WebSocket connection from a full URL. | |
| uint64 | createWebsocketConnection (const char *uri, const char *addr, uint16 port, uint8 encryption, const char *protocolName, const char *origin=NULL, uint32 timeoutMS=5000) |
| Open a client WebSocket connection from explicit components. | |
| bool | endConnection (uint64 conid) |
| Gracefully close a connection. | |
| bool | endUDPConnection (uint16 port) |
Close the UDP connection bound to port. | |
| uint8 | getConnectionType (uint64 conid) |
| uint64 | getRemoteAddress (uint64 conid) |
| uint64 | autoDetectConnection (NetworkConnection *con, uint16 port, uint32 autoProtocols, uint32 autoProtocolTimeout, uint32 defaultProtocol, bool isAsync, bool autoreconnect) |
Adopt an incoming connection whose protocol is not yet known: sniff its first bytes against autoProtocols and start the matching handler thread. | |
| uint64 | startConnection (NetworkConnection *con, uint8 protocol, bool isAsync, bool autoreconnect, uint32 timeoutMS=5000) |
| Start the protocol worker thread for an already-connected connection. | |
| bool | setSSLAllowSelfSigned (bool allow) |
| bool | setSSLCALocation (const char *caFile, const char *caPath) |
| void | applySSLClientPolicy (SSLConnection *con) |
| bool | setNewReceiver (NetworkReceiver *recv) |
| Replace the channel's receiver for async dispatch. | |
| NetworkEvent * | waitForNetworkEvent (uint32 ms) |
| Wait for the next connection lifecycle event (sync mode). | |
| HTTPRequest * | waitForHTTPRequest (uint64 &conid, uint32 ms) |
| Wait for the next queued HTTP request (sync-mode HTTP server). | |
| TelnetLine * | waitForTelnetLine (uint64 &conid, uint32 ms) |
| Wait for the next queued Telnet line. | |
| DataMessage * | waitForMessage (uint64 &conid, uint32 ms) |
| Wait for the next queued DataMessage. | |
| HTTPReply * | waitForHTTPReply (uint64 &conid, uint32 ms) |
| Wait for the next queued HTTP reply (sync-mode HTTP client). | |
| WebsocketData * | waitForWebsocketData (uint64 &conid, uint32 ms) |
| Wait for the next queued WebSocket message. | |
| bool | sendHTTPReply (HTTPReply *reply, uint64 conid) |
| Send an HTTP reply on a server connection. | |
| bool | sendTelnetLine (TelnetLine *line, uint64 conid) |
| Send a Telnet line. | |
| bool | sendMessage (DataMessage *msg, uint64 conid) |
| Send a DataMessage. | |
| bool | sendHTTPRequest (HTTPRequest *req, uint64 conid) |
| Send an HTTP request without waiting for the reply (reply arrives via receiveHTTPReply()/waitForHTTPReply()). | |
| HTTPReply * | sendReceiveHTTPRequest (HTTPRequest *req, uint64 conid, uint32 timeout) |
| Send an HTTP request and block for its reply on the same connection. | |
| TelnetLine * | sendReceiveTelnetLine (TelnetLine *line, uint64 conid, uint32 timeout, uint32 size=0) |
| Send a Telnet line and block for the response line. | |
| bool | sendWebsocketData (WebsocketData *wsData, uint64 conid) |
| Send a WebSocket frame. | |
| uint32 | getOutputSpeed (uint64 conid) |
| uint32 | getInputSpeed (uint64 conid) |
Public Attributes | |
| uint32 | cid |
| Channel id within the manager. | |
| int8 | sslAllowSelfSigned |
| std::string | sslCAFile |
| std::string | sslCAPath |
| bool | sslCASet |
Protected Member Functions | |
| bool | enterNetworkEvent (uint8 type, uint8 protocol, uint64 conid) |
| Queue or push a lifecycle event. | |
| bool | enterHTTPRequest (HTTPRequest *req, uint64 conid) |
| Queue or push an incoming HTTP request. | |
| bool | enterHTTPReply (HTTPReply *reply, HTTPRequest *req, uint64 conid) |
| Queue or push an incoming HTTP reply. | |
| bool | enterMessage (DataMessage *msg, uint64 conid) |
| Queue or push an incoming DataMessage. | |
| bool | enterTelnetLine (TelnetLine *line, uint64 conid) |
| Queue or push an incoming Telnet line. | |
| bool | enterWebsocketData (WebsocketData *wsData, uint64 conid) |
| Queue or push an incoming WebSocket message. | |
Static Protected Member Functions | |
| static THREAD_RET THREAD_FUNCTION_CALL | NetworkListenerRun (THREAD_ARG arg) |
| Thread entry: accept loop for a TCP listener. | |
| static THREAD_RET THREAD_FUNCTION_CALL | ConnectionAutodetectRun (THREAD_ARG arg) |
| Thread entry: protocol sniffing for a fresh connection (see autoDetectConnection()). | |
| static THREAD_RET THREAD_FUNCTION_CALL | HTTPClientRun (THREAD_ARG arg) |
| Thread entry: HTTP client connection loop (send requests, parse replies). | |
| static THREAD_RET THREAD_FUNCTION_CALL | HTTPServerRun (THREAD_ARG arg) |
| Thread entry: HTTP/WebSocket server connection loop — the built-in web server's per-connection worker (parses requests, dispatches, sends replies, handles the WebSocket upgrade and subsequent frames). | |
| static THREAD_RET THREAD_FUNCTION_CALL | MessageConnectionRun (THREAD_ARG arg) |
| Thread entry: binary DataMessage connection loop. | |
| static THREAD_RET THREAD_FUNCTION_CALL | TelnetServerRun (THREAD_ARG arg) |
| Thread entry: Telnet server connection loop. | |
Friends | |
| class | NetworkManager |
One logical network interface: a group of listeners/connections with shared dispatch.
A channel bundles related listeners and connections (e.g. "the web interface on port 8080" or "the gateway link"), gives each its own worker thread, and funnels all parsed traffic either to the channel's NetworkReceiver (async) or into typed wait queues consumed via the waitFor*() methods (sync). Send methods are addressed by connection id.
Channels are created and owned by NetworkManager; user code normally obtains one from the manager's factory methods rather than constructing it directly.
Definition at line 424 of file NetworkManager.h.
| cmlabs::NetworkChannel::NetworkChannel | ( | NetworkManager * | manager | ) |
| manager | Owning manager (not owned by the channel). |
Definition at line 675 of file NetworkManager.cpp.
References manager, NetworkManager, receiver, sslAllowSelfSigned, and sslCASet.
Referenced by HTTPClientRun(), HTTPServerRun(), MessageConnectionRun(), and TelnetServerRun().
|
virtual |
Definition at line 703 of file NetworkManager.cpp.
References manager, and shutdown().
| uint64 cmlabs::NetworkChannel::addTCPConnection | ( | const char * | addr, |
| uint16 | port, | ||
| uint8 | encryption, | ||
| uint8 | protocol, | ||
| bool | isAsync, | ||
| uint64 & | location, | ||
| uint32 | timeoutMS = 5000, | ||
| const char * | greetingData = NULL, | ||
| uint32 | greetingSize = 0 ) |
Connect with optional greeting bytes (no autoreconnect); see NetworkManager::addTCPConnection().
Definition at line 992 of file NetworkManager.cpp.
References applySSLClientPolicy(), cmlabs::SSLConnection::delayedConnect(), cmlabs::TCPConnection::delayedConnect(), cmlabs::SSLConnection::init(), NOENC, cmlabs::NetworkConnection::setGreetingData(), SSLENC, and startConnection().
Referenced by cmlabs::NetworkManager::addTCPConnection(), cmlabs::NetworkManager::addTCPConnection(), and cmlabs::NetworkManager::UnitTestDelayedConnect().
| uint64 cmlabs::NetworkChannel::addTCPConnection | ( | uint64 | location, |
| uint8 | encryption, | ||
| uint8 | protocol, | ||
| bool | isAsync, | ||
| uint32 | timeoutMS = 5000, | ||
| const char * | greetingData = NULL, | ||
| uint32 | greetingSize = 0 ) |
Packed-endpoint variant of addTCPConnection().
Definition at line 1022 of file NetworkManager.cpp.
References applySSLClientPolicy(), cmlabs::SSLConnection::delayedConnect(), cmlabs::TCPConnection::delayedConnect(), cmlabs::SSLConnection::init(), NOENC, cmlabs::NetworkConnection::setGreetingData(), SSLENC, and startConnection().
| void cmlabs::NetworkChannel::applySSLClientPolicy | ( | SSLConnection * | con | ) |
Definition at line 686 of file NetworkManager.cpp.
References manager, cmlabs::SSLConnection::setAllowSelfSigned(), cmlabs::SSLConnection::setCALocation(), sslAllowSelfSigned, sslCAFile, sslCAPath, and sslCASet.
Referenced by addTCPConnection(), addTCPConnection(), createTCPConnection(), createTCPConnection(), createTCPConnection(), and createWebsocketConnection().
| uint64 cmlabs::NetworkChannel::autoDetectConnection | ( | NetworkConnection * | con, |
| uint16 | port, | ||
| uint32 | autoProtocols, | ||
| uint32 | autoProtocolTimeout, | ||
| uint32 | defaultProtocol, | ||
| bool | isAsync, | ||
| bool | autoreconnect ) |
Adopt an incoming connection whose protocol is not yet known: sniff its first bytes against autoProtocols and start the matching handler thread.
| con | The fresh connection (ownership transfers). |
| port | Listener port it arrived on. |
| autoProtocols | PROTOCOL_* bit set to test. |
| autoProtocolTimeout | Max sniffing time in ms. |
| defaultProtocol | Fallback protocol when detection is inconclusive (0 = drop). |
| isAsync | Push vs queue dispatch. |
| autoreconnect | Reconnect on failure. |
Definition at line 1516 of file NetworkManager.cpp.
References cmlabs::NetworkThread::autoProtocols, cmlabs::NetworkThread::autoProtocolTimeout, cmlabs::NetworkThread::autoreconnect, channelMutex, cmlabs::NetworkThread::con, ConnectionAutodetectRun(), connectionThreads, cmlabs::ThreadManager::CreateThread(), cmlabs::NetworkThread::defaultProtocol, cmlabs::NetworkThread::isAsync, manager, cmlabs::NetworkThread::parent, and cmlabs::NetworkThread::threadID.
Referenced by NetworkListenerRun().
|
staticprotected |
Thread entry: protocol sniffing for a fresh connection (see autoDetectConnection()).
Definition at line 1625 of file NetworkManager.cpp.
References cmlabs::NetworkThread::autoProtocols, cmlabs::NetworkThread::autoProtocolTimeout, cmlabs::HTTPProtocol::CheckBufferForCompatibility(), cmlabs::MessageProtocol::CheckBufferForCompatibility(), cmlabs::TelnetProtocol::CheckBufferForCompatibility(), cmlabs::NetworkThread::con, cmlabs::NetworkThread::defaultProtocol, enterNetworkEvent(), cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), HTTPClientRun(), HTTPServerRun(), cmlabs::NetworkThread::id, cmlabs::NetworkThread::isRunning, LOG_NETWORK, LogPrint, MessageConnectionRun(), NETWORKEVENT_CONNECT, cmlabs::NetworkThread::parent, PROTOCOL_HTTP_CLIENT, PROTOCOL_HTTP_SERVER, PROTOCOL_MESSAGE, PROTOCOL_TELNET, cmlabs::NetworkConnection::receiveAvailable(), cmlabs::NetworkThread::shouldContinue, TelnetServerRun(), THREAD_ARG, THREAD_FUNCTION_CALL, THREAD_RET, and thread_ret_val.
Referenced by autoDetectConnection().
| uint64 cmlabs::NetworkChannel::createTCPConnection | ( | const char * | addr, |
| uint16 | port, | ||
| uint8 | encryption, | ||
| uint8 | protocol, | ||
| bool | isAsync, | ||
| bool | autoreconnect, | ||
| uint64 & | location, | ||
| uint32 | timeoutMS = 5000 ) |
Connect to a host by name/IP; see NetworkManager::createTCPConnection().
timeoutMS. Definition at line 922 of file NetworkManager.cpp.
References applySSLClientPolicy(), cmlabs::SSLConnection::connect(), cmlabs::TCPConnection::connect(), cmlabs::SSLConnection::init(), NOENC, SSLENC, and startConnection().
Referenced by cmlabs::NetworkManager::createTCPConnection(), cmlabs::NetworkManager::createTCPConnection(), and cmlabs::NetworkManager::createTCPConnection().
| uint64 cmlabs::NetworkChannel::createTCPConnection | ( | const uint32 * | addresses, |
| uint16 | addressCount, | ||
| uint16 | port, | ||
| uint8 | encryption, | ||
| uint8 | protocol, | ||
| bool | isAsync, | ||
| bool | autoreconnect, | ||
| uint64 & | location, | ||
| uint32 | timeoutMS = 5000 ) |
Connect trying several candidate addresses.
Definition at line 970 of file NetworkManager.cpp.
References applySSLClientPolicy(), cmlabs::SSLConnection::connect(), cmlabs::TCPConnection::connect(), NOENC, SSLENC, and startConnection().
| uint64 cmlabs::NetworkChannel::createTCPConnection | ( | uint64 | location, |
| uint8 | encryption, | ||
| uint8 | protocol, | ||
| bool | isAsync, | ||
| bool | autoreconnect, | ||
| uint32 | timeoutMS = 5000 ) |
Connect to a packed uint64 endpoint.
Definition at line 948 of file NetworkManager.cpp.
References applySSLClientPolicy(), cmlabs::SSLConnection::connect(), cmlabs::TCPConnection::connect(), NOENC, SSLENC, and startConnection().
| uint64 cmlabs::NetworkChannel::createUDPConnection | ( | uint16 | port, |
| uint8 | protocol, | ||
| bool | isAsync, | ||
| bool | autoreconnect ) |
Bind a UDP port on this channel.
Definition at line 1131 of file NetworkManager.cpp.
References channelMutex, cmlabs::UDPConnection::connect(), connectionThreads, startConnection(), and udpListeners.
Referenced by cmlabs::NetworkManager::createUDPConnection().
| uint64 cmlabs::NetworkChannel::createWebsocketConnection | ( | const char * | uri, |
| const char * | addr, | ||
| uint16 | port, | ||
| uint8 | encryption, | ||
| const char * | protocolName, | ||
| const char * | origin = NULL, | ||
| uint32 | timeoutMS = 5000 ) |
Open a client WebSocket connection from explicit components.
Definition at line 1084 of file NetworkManager.cpp.
References applySSLClientPolicy(), cmlabs::SSLConnection::connect(), cmlabs::TCPConnection::connect(), cmlabs::HTTPRequest::CreateWebsocketRequest(), endConnection(), HTTP_SWITCH_PROTOCOL, NOENC, PROTOCOL_HTTP_CLIENT, cmlabs::HTTPProtocol::SendHTTPRequest(), SSLENC, startConnection(), cmlabs::HTTPReply::type, and waitForHTTPReply().
| uint64 cmlabs::NetworkChannel::createWebsocketConnection | ( | const char * | url, |
| const char * | protocolName, | ||
| const char * | origin = NULL, | ||
| uint32 | timeoutMS = 5000 ) |
Open a client WebSocket connection from a full URL.
Definition at line 1053 of file NetworkManager.cpp.
References createWebsocketConnection(), cmlabs::html::GetHostFromURL(), cmlabs::html::GetPortFromURL(), cmlabs::html::GetProtocolFromURL(), cmlabs::html::GetURIFromURL(), NOENC, and SSLENC.
Referenced by createWebsocketConnection(), cmlabs::NetworkManager::createWebsocketConnection(), cmlabs::NetworkManager::createWebsocketConnection(), and cmlabs::TestWebSocketRequestClient::run().
| bool cmlabs::NetworkChannel::endConnection | ( | uint64 | conid | ) |
Gracefully close a connection.
| conid | Connection id. |
Definition at line 1182 of file NetworkManager.cpp.
References cmlabs::NetworkThread::autoreconnect, channelMutex, connectionThreads, cmlabs::utils::GetCurrentThreadUniqueID(), cmlabs::ThreadManager::GetThreadStats(), cmlabs::NetworkThread::isRunning, cmlabs::ThreadManager::IsThreadRunning(), manager, cmlabs::ThreadStats::osID, cmlabs::NetworkThread::shouldContinue, cmlabs::utils::Sleep(), cmlabs::ThreadManager::TerminateThread(), and cmlabs::NetworkThread::threadID.
Referenced by createWebsocketConnection(), cmlabs::NetworkManager::endConnection(), endUDPConnection(), HTTPClientRun(), HTTPServerRun(), cmlabs::NetworkManager::makeHTTPRequest(), cmlabs::NetworkManager::makeHTTPRequest(), cmlabs::NetworkManager::makeHTTPRequest(), MessageConnectionRun(), cmlabs::TestWebSocketRequestClient::run(), TelnetServerRun(), cmlabs::NetworkManager::TestHTTP(), cmlabs::NetworkManager::UnitTest(), cmlabs::NetworkManager::UnitTestHTTP(), and cmlabs::NetworkManager::WebsocketTest().
| bool cmlabs::NetworkChannel::endUDPConnection | ( | uint16 | port | ) |
Close the UDP connection bound to port.
Definition at line 1152 of file NetworkManager.cpp.
References channelMutex, endConnection(), cmlabs::NetworkThread::id, and udpListeners.
Referenced by cmlabs::NetworkManager::endUDPConnection().
|
protected |
Queue or push an incoming HTTP reply.
Definition at line 1467 of file NetworkManager.cpp.
References queueHTTPReplies, queueHTTPRepliesMutex, queueHTTPRepliesSemaphore, and receiver.
Referenced by HTTPClientRun().
|
protected |
Queue or push an incoming HTTP request.
Definition at line 1447 of file NetworkManager.cpp.
References queueHTTPRequests, queueHTTPRequestsMutex, queueHTTPRequestsSemaphore, and receiver.
Referenced by HTTPServerRun().
|
protected |
Queue or push an incoming DataMessage.
Definition at line 1477 of file NetworkManager.cpp.
References queueMessageConIDs, queueMessages, queueMessagesMutex, queueMessagesSemaphore, and receiver.
Referenced by MessageConnectionRun().
|
protected |
Queue or push a lifecycle event.
Definition at line 1500 of file NetworkManager.cpp.
References cid, cmlabs::NetworkEvent::cid, cmlabs::NetworkEvent::conid, eventQueue, eventQueueMutex, eventQueueSemaphore, cmlabs::GetTimeNow(), cmlabs::NetworkEvent::protocol, receiver, cmlabs::NetworkEvent::time, and cmlabs::NetworkEvent::type.
Referenced by ConnectionAutodetectRun(), HTTPClientRun(), HTTPServerRun(), MessageConnectionRun(), and TelnetServerRun().
|
protected |
Queue or push an incoming Telnet line.
Definition at line 1489 of file NetworkManager.cpp.
References queueTelnetLines, queueTelnetLinesMutex, queueTelnetLinesSemaphore, and receiver.
Referenced by TelnetServerRun().
|
protected |
Queue or push an incoming WebSocket message.
Definition at line 1457 of file NetworkManager.cpp.
References queueWebsocketData, queueWebsocketDataMutex, queueWebsocketDataSemaphore, and receiver.
Referenced by HTTPClientRun(), and HTTPServerRun().
| uint8 cmlabs::NetworkChannel::getConnectionType | ( | uint64 | conid | ) |
| conid | Connection id. |
Definition at line 1168 of file NetworkManager.cpp.
References cmlabs::NetworkThread::con, connectionThreads, and cmlabs::NetworkConnection::getConnectionType().
Referenced by cmlabs::NetworkManager::getConnectionType().
| uint32 cmlabs::NetworkChannel::getInputSpeed | ( | uint64 | conid | ) |
| conid | Connection id. |
Definition at line 1424 of file NetworkManager.cpp.
References cmlabs::NetworkThread::con, connectionThreads, and cmlabs::NetworkConnection::getInputSpeed().
| uint32 cmlabs::NetworkChannel::getOutputSpeed | ( | uint64 | conid | ) |
| conid | Connection id. |
Definition at line 1417 of file NetworkManager.cpp.
References cmlabs::NetworkThread::con, connectionThreads, and cmlabs::NetworkConnection::getOutputSpeed().
| uint64 cmlabs::NetworkChannel::getRemoteAddress | ( | uint64 | conid | ) |
| conid | Connection id. |
Definition at line 1175 of file NetworkManager.cpp.
References cmlabs::NetworkThread::con, connectionThreads, and cmlabs::NetworkConnection::getRemoteAddress().
Referenced by cmlabs::NetworkManager::getRemoteAddress().
|
staticprotected |
Thread entry: HTTP client connection loop (send requests, parse replies).
Definition at line 1742 of file NetworkManager.cpp.
References cmlabs::NetworkThread::autoreconnect, cmlabs::NetworkThread::con, cmlabs::NetworkThread::defaultProtocol, cmlabs::NetworkConnection::disconnect(), endConnection(), enterHTTPReply(), enterNetworkEvent(), enterWebsocketData(), cmlabs::NetworkConnection::greetingData, cmlabs::NetworkConnection::greetingSize, cmlabs::NetworkThread::id, cmlabs::NetworkConnection::isConnected(), cmlabs::NetworkThread::isRunning, cmlabs::WebsocketData::isTerminationRequest(), cmlabs::HTTPReply::isWebsocketUpgrade(), NetworkChannel(), NETWORKERROR_GREETING_ERROR, NETWORKEVENT_DISCONNECT, NETWORKEVENT_DISCONNECT_RETRYING, NETWORKEVENT_RECONNECT, NETWORKEVENT_UNPROCESSED_DATA, cmlabs::NetworkThread::parent, cmlabs::HTTPProtocol::ReceiveHTTPReply(), cmlabs::HTTPProtocol::ReceiveWebsocketData(), cmlabs::NetworkConnection::reconnect(), cmlabs::NetworkConnection::send(), cmlabs::NetworkThread::shouldContinue, cmlabs::utils::Sleep(), THREAD_ARG, THREAD_FUNCTION_CALL, THREAD_RET, and thread_ret_val.
Referenced by ConnectionAutodetectRun(), and startConnection().
|
staticprotected |
Thread entry: HTTP/WebSocket server connection loop — the built-in web server's per-connection worker (parses requests, dispatches, sends replies, handles the WebSocket upgrade and subsequent frames).
Definition at line 1848 of file NetworkManager.cpp.
References cmlabs::NetworkThread::con, cmlabs::HTTPRequest::contentLength, cmlabs::HTTPReply::CreateErrorReply(), cmlabs::WebsocketData::CreateTerminationConfirmation(), cmlabs::HTTPReply::CreateWebsocketHTTPReply(), cmlabs::NetworkThread::defaultProtocol, endConnection(), enterHTTPRequest(), enterNetworkEvent(), enterWebsocketData(), cmlabs::HTTPRequest::getHeaderEntry(), cmlabs::HTTPRequest::headerLength, HTTP_ACCESS_DENIED, cmlabs::NetworkThread::id, cmlabs::NetworkConnection::isConnected(), cmlabs::NetworkThread::isRunning, cmlabs::WebsocketData::isTerminationRequest(), cmlabs::HTTPRequest::isWebsocketUpgrade(), LOG_NETWORK, LogPrint, NetworkChannel(), NETWORKEVENT_DISCONNECT, NETWORKEVENT_PROTOCOL_ERROR, NETWORKEVENT_UNPROCESSED_DATA, cmlabs::NetworkThread::parent, cmlabs::HTTPProtocol::ReceiveHTTPRequest(), cmlabs::HTTPProtocol::ReceiveWebsocketData(), sendHTTPReply(), sendWebsocketData(), cmlabs::NetworkThread::shouldContinue, THREAD_ARG, THREAD_FUNCTION_CALL, THREAD_RET, and thread_ret_val.
Referenced by ConnectionAutodetectRun(), and startConnection().
| bool cmlabs::NetworkChannel::isConnected | ( | uint64 | conid | ) |
| conid | Connection id. |
Definition at line 708 of file NetworkManager.cpp.
References cmlabs::NetworkThread::con, connectionThreads, and cmlabs::NetworkConnection::isConnected().
|
staticprotected |
Thread entry: binary DataMessage connection loop.
Definition at line 1966 of file NetworkManager.cpp.
References cmlabs::NetworkThread::autoreconnect, cmlabs::NetworkThread::con, cmlabs::NetworkThread::defaultProtocol, cmlabs::NetworkConnection::disconnect(), endConnection(), enterMessage(), enterNetworkEvent(), cmlabs::NetworkConnection::getRemoteAddress(), cmlabs::GetTimeNow(), cmlabs::NetworkConnection::greetingData, cmlabs::NetworkConnection::greetingSize, cmlabs::NetworkThread::id, cmlabs::NetworkConnection::isConnected(), cmlabs::NetworkThread::isRunning, NetworkChannel(), NETWORKERROR_GREETING_ERROR, NETWORKEVENT_DISCONNECT, NETWORKEVENT_DISCONNECT_RETRYING, NETWORKEVENT_RECONNECT, NETWORKEVENT_UNPROCESSED_DATA, cmlabs::NetworkThread::parent, cmlabs::MessageProtocol::ReceiveMessage(), cmlabs::NetworkConnection::reconnect(), cmlabs::NetworkConnection::send(), cmlabs::NetworkThread::shouldContinue, cmlabs::utils::Sleep(), THREAD_ARG, THREAD_FUNCTION_CALL, THREAD_RET, and thread_ret_val.
Referenced by ConnectionAutodetectRun(), and startConnection().
|
staticprotected |
Thread entry: accept loop for a TCP listener.
Definition at line 1601 of file NetworkManager.cpp.
References cmlabs::TCPListener::acceptConnection(), autoDetectConnection(), cmlabs::NetworkThread::autoProtocols, cmlabs::NetworkThread::autoProtocolTimeout, cmlabs::NetworkThread::defaultProtocol, cmlabs::NetworkThread::isAsync, cmlabs::NetworkThread::isRunning, cmlabs::NetworkThread::listener, cmlabs::NetworkThread::parent, cmlabs::NetworkThread::port, cmlabs::NetworkThread::shouldContinue, THREAD_ARG, THREAD_FUNCTION_CALL, THREAD_RET, and thread_ret_val.
Referenced by startListener().
| bool cmlabs::NetworkChannel::sendHTTPReply | ( | HTTPReply * | reply, |
| uint64 | conid ) |
Send an HTTP reply on a server connection.
| reply | Reply (caller keeps ownership). |
| conid | Destination connection. |
Definition at line 1360 of file NetworkManager.cpp.
References cmlabs::NetworkThread::con, connectionThreads, and cmlabs::HTTPProtocol::SendHTTPReply().
Referenced by HTTPServerRun(), and cmlabs::HTTPTestServer::receiveHTTPRequest().
| bool cmlabs::NetworkChannel::sendHTTPRequest | ( | HTTPRequest * | req, |
| uint64 | conid ) |
Send an HTTP request without waiting for the reply (reply arrives via receiveHTTPReply()/waitForHTTPReply()).
| req | Request (caller keeps ownership). |
| conid | Destination. |
Definition at line 1431 of file NetworkManager.cpp.
References cmlabs::NetworkThread::con, connectionThreads, and cmlabs::HTTPProtocol::SendHTTPRequest().
| bool cmlabs::NetworkChannel::sendMessage | ( | DataMessage * | msg, |
| uint64 | conid ) |
Send a DataMessage.
| msg | Message (caller keeps ownership). |
| conid | Destination. |
Definition at line 1395 of file NetworkManager.cpp.
References cmlabs::NetworkThread::con, connectionThreads, and cmlabs::MessageProtocol::SendMessage().
Referenced by cmlabs::Test_RequestClient(), and cmlabs::NetworkManager::UnitTest().
| HTTPReply * cmlabs::NetworkChannel::sendReceiveHTTPRequest | ( | HTTPRequest * | req, |
| uint64 | conid, | ||
| uint32 | timeout ) |
Send an HTTP request and block for its reply on the same connection.
| req | Request (caller keeps ownership). |
| conid | Destination. |
| timeout | Max wait in ms. |
Definition at line 1405 of file NetworkManager.cpp.
References cmlabs::NetworkThread::con, connectionThreads, cmlabs::HTTPReply::CreateErrorReply(), HTTP_SERVER_UNAVAILABLE, cmlabs::HTTPProtocol::SendHTTPRequest(), and waitForHTTPReply().
Referenced by cmlabs::HTTPServerTest(), cmlabs::NetworkManager::makeHTTPRequest(), cmlabs::NetworkManager::makeHTTPRequest(), cmlabs::NetworkManager::makeHTTPRequest(), cmlabs::NetworkManager::UnitTestHTTP(), and cmlabs::NetworkManager::WebsocketTest().
| TelnetLine * cmlabs::NetworkChannel::sendReceiveTelnetLine | ( | TelnetLine * | line, |
| uint64 | conid, | ||
| uint32 | timeout, | ||
| uint32 | size = 0 ) |
Send a Telnet line and block for the response line.
| line | Line to send (caller keeps ownership). |
| conid | Destination. |
| timeout | Max wait in ms. |
| size | Exact response byte count (0 = up to CR/LF). |
Definition at line 1376 of file NetworkManager.cpp.
References cmlabs::NetworkConnection::clearBuffer(), cmlabs::NetworkThread::con, connectionThreads, cmlabs::NetworkThread::isAsync, cmlabs::TelnetProtocol::ReceiveTelnetLine(), and cmlabs::TelnetProtocol::SendTelnetLine().
| bool cmlabs::NetworkChannel::sendTelnetLine | ( | TelnetLine * | line, |
| uint64 | conid ) |
Send a Telnet line.
| line | Line (caller keeps ownership). |
| conid | Destination. |
Definition at line 1368 of file NetworkManager.cpp.
References cmlabs::NetworkThread::con, connectionThreads, and cmlabs::TelnetProtocol::SendTelnetLine().
| bool cmlabs::NetworkChannel::sendWebsocketData | ( | WebsocketData * | wsData, |
| uint64 | conid ) |
Send a WebSocket frame.
| wsData | Frame (caller keeps ownership). |
| conid | Destination. |
Definition at line 1352 of file NetworkManager.cpp.
References cmlabs::NetworkThread::con, connectionThreads, and cmlabs::HTTPProtocol::SendWebsocketData().
Referenced by HTTPServerRun(), cmlabs::WebsocketTestServer::receiveWebsocketData(), and cmlabs::TestWebSocketRequestClient::run().
| bool cmlabs::NetworkChannel::setNewReceiver | ( | NetworkReceiver * | recv | ) |
Replace the channel's receiver for async dispatch.
| recv | New receiver (not owned; must outlive the channel or be replaced). |
Definition at line 1236 of file NetworkManager.cpp.
References receiver.
Referenced by cmlabs::NetworkManager::addTCPConnection(), cmlabs::NetworkManager::addTCPConnection(), cmlabs::NetworkManager::createListener(), cmlabs::NetworkManager::createTCPConnection(), cmlabs::NetworkManager::createTCPConnection(), cmlabs::NetworkManager::createTCPConnection(), cmlabs::NetworkManager::createUDPConnection(), cmlabs::NetworkManager::createWebsocketConnection(), and cmlabs::NetworkManager::createWebsocketConnection().
|
inline |
Definition at line 498 of file NetworkManager.h.
References sslAllowSelfSigned.
|
inline |
Definition at line 502 of file NetworkManager.h.
| bool cmlabs::NetworkChannel::shutdown | ( | ) |
Stop all worker threads and close all listeners/connections of this channel.
Definition at line 716 of file NetworkManager.cpp.
References cmlabs::NetworkThread::autoreconnect, channelMutex, connectionThreads, eventQueue, eventQueueMutex, cmlabs::NetworkThread::isRunning, cmlabs::ThreadManager::IsThreadRunning(), listeners, queueHTTPReplies, queueHTTPRepliesMutex, queueHTTPRequests, queueHTTPRequestsMutex, queueMessageConIDs, queueMessages, queueMessagesMutex, queueTelnetLines, queueTelnetLinesMutex, queueWebsocketData, queueWebsocketDataMutex, cmlabs::NetworkThread::shouldContinue, cmlabs::utils::Sleep(), cmlabs::ThreadManager::TerminateThread(), and cmlabs::NetworkThread::threadID.
Referenced by ~NetworkChannel().
| uint64 cmlabs::NetworkChannel::startConnection | ( | NetworkConnection * | con, |
| uint8 | protocol, | ||
| bool | isAsync, | ||
| bool | autoreconnect, | ||
| uint32 | timeoutMS = 5000 ) |
Start the protocol worker thread for an already-connected connection.
| con | The connection (ownership transfers). |
| protocol | Single PROTOCOL_* flag. |
| isAsync | Push vs queue dispatch. |
| autoreconnect | Reconnect on failure. |
| timeoutMS | Timeout used during any initial exchange. |
Definition at line 1557 of file NetworkManager.cpp.
References cmlabs::NetworkThread::autoreconnect, channelMutex, cmlabs::NetworkThread::con, connectionThreads, cmlabs::ThreadManager::CreateThread(), cmlabs::NetworkThread::defaultProtocol, HTTPClientRun(), HTTPServerRun(), cmlabs::NetworkThread::isAsync, manager, MessageConnectionRun(), PROTOCOL_HTTP_CLIENT, PROTOCOL_HTTP_SERVER, PROTOCOL_MESSAGE, PROTOCOL_TELNET, cmlabs::NetworkConnection::setConnectTimeout(), TelnetServerRun(), and cmlabs::NetworkThread::threadID.
Referenced by addTCPConnection(), addTCPConnection(), createTCPConnection(), createTCPConnection(), createTCPConnection(), cmlabs::NetworkManager::createTCPConnection(), createUDPConnection(), and createWebsocketConnection().
| bool cmlabs::NetworkChannel::startListener | ( | uint64 | cid, |
| uint16 | port, | ||
| uint8 | encryption, | ||
| uint8 | protocol, | ||
| bool | isAsync, | ||
| uint32 | protocolTimeout = 3000, | ||
| bool | isDefaultProtocol = false ) |
Open a listener on this channel (see NetworkManager::createListener() for semantics).
| cid | Channel id to tag events with. |
| port | TCP port. |
| encryption | NOENC or SSLENC. |
| protocol | PROTOCOL_* flags. |
| isAsync | Push vs queue dispatch. |
| protocolTimeout | Sniffing timeout in ms. |
| isDefaultProtocol | First flag is the fallback. |
Definition at line 839 of file NetworkManager.cpp.
References cmlabs::NetworkThread::autoProtocols, cmlabs::NetworkThread::autoProtocolTimeout, channelMutex, cid, cmlabs::ThreadManager::CreateThread(), cmlabs::NetworkThread::defaultProtocol, cmlabs::TCPListener::init(), cmlabs::NetworkThread::isAsync, cmlabs::NetworkThread::listener, listeners, manager, NetworkListenerRun(), cmlabs::NetworkThread::port, cmlabs::TCPListener::setSSLCertificate(), and cmlabs::NetworkThread::threadID.
Referenced by cmlabs::NetworkManager::createListener().
| bool cmlabs::NetworkChannel::stopListener | ( | uint16 | port, |
| uint8 | protocol ) |
Stop a listener on this channel.
| port | Port. |
| protocol | Its PROTOCOL_* flags. |
Definition at line 898 of file NetworkManager.cpp.
References cmlabs::NetworkThread::autoProtocols, channelMutex, cmlabs::NetworkThread::defaultProtocol, cmlabs::NetworkThread::isRunning, listeners, cmlabs::NetworkThread::shouldContinue, cmlabs::utils::Sleep(), cmlabs::ThreadManager::TerminateThread(), and cmlabs::NetworkThread::threadID.
Referenced by cmlabs::NetworkManager::stopListener().
|
staticprotected |
Thread entry: Telnet server connection loop.
Definition at line 2078 of file NetworkManager.cpp.
References cmlabs::NetworkThread::con, cmlabs::NetworkThread::defaultProtocol, endConnection(), enterNetworkEvent(), enterTelnetLine(), cmlabs::NetworkThread::id, cmlabs::NetworkThread::isAsync, cmlabs::NetworkConnection::isConnected(), cmlabs::NetworkThread::isRunning, NetworkChannel(), NETWORKEVENT_DISCONNECT, NETWORKEVENT_UNPROCESSED_DATA, cmlabs::NetworkThread::parent, cmlabs::TelnetProtocol::ReceiveTelnetLine(), cmlabs::NetworkThread::shouldContinue, cmlabs::utils::Sleep(), THREAD_ARG, THREAD_FUNCTION_CALL, THREAD_RET, and thread_ret_val.
Referenced by ConnectionAutodetectRun(), and startConnection().
| HTTPReply * cmlabs::NetworkChannel::waitForHTTPReply | ( | uint64 & | conid, |
| uint32 | ms ) |
Wait for the next queued HTTP reply (sync-mode HTTP client).
| conid | Out: source connection. |
| ms | Max wait in ms. |
Definition at line 1333 of file NetworkManager.cpp.
References cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), queueHTTPReplies, queueHTTPRepliesMutex, and queueHTTPRepliesSemaphore.
Referenced by createWebsocketConnection(), and sendReceiveHTTPRequest().
| HTTPRequest * cmlabs::NetworkChannel::waitForHTTPRequest | ( | uint64 & | conid, |
| uint32 | ms ) |
Wait for the next queued HTTP request (sync-mode HTTP server).
| conid | Out: connection the request arrived on (use with sendHTTPReply()). |
| ms | Max wait in ms. |
Definition at line 1259 of file NetworkManager.cpp.
References cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), queueHTTPRequests, queueHTTPRequestsMutex, and queueHTTPRequestsSemaphore.
| DataMessage * cmlabs::NetworkChannel::waitForMessage | ( | uint64 & | conid, |
| uint32 | ms ) |
Wait for the next queued DataMessage.
| conid | Out: source connection. |
| ms | Max wait in ms. |
Definition at line 1310 of file NetworkManager.cpp.
References cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), queueMessageConIDs, queueMessages, queueMessagesMutex, and queueMessagesSemaphore.
Referenced by cmlabs::Test_RequestClient(), cmlabs::NetworkManager::UnitTest(), and cmlabs::NetworkManager::UnitTestDelayedConnect().
| NetworkEvent * cmlabs::NetworkChannel::waitForNetworkEvent | ( | uint32 | ms | ) |
Wait for the next connection lifecycle event (sync mode).
| ms | Max wait in milliseconds. |
Definition at line 1242 of file NetworkManager.cpp.
References eventQueue, eventQueueMutex, eventQueueSemaphore, cmlabs::GetTimeAgeMS(), and cmlabs::GetTimeNow().
| TelnetLine * cmlabs::NetworkChannel::waitForTelnetLine | ( | uint64 & | conid, |
| uint32 | ms ) |
Wait for the next queued Telnet line.
| conid | Out: source connection. |
| ms | Max wait in ms. |
Definition at line 1293 of file NetworkManager.cpp.
References cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), queueTelnetLines, queueTelnetLinesMutex, and queueTelnetLinesSemaphore.
| WebsocketData * cmlabs::NetworkChannel::waitForWebsocketData | ( | uint64 & | conid, |
| uint32 | ms ) |
Wait for the next queued WebSocket message.
| conid | Out: source connection. |
| ms | Max wait in ms. |
Definition at line 1276 of file NetworkManager.cpp.
References cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), queueWebsocketData, queueWebsocketDataMutex, and queueWebsocketDataSemaphore.
Referenced by cmlabs::TestWebSocketRequestClient::run().
|
friend |
Definition at line 425 of file NetworkManager.h.
References manager, and NetworkManager.
Referenced by NetworkChannel(), and NetworkManager.
|
protected |
Definition at line 611 of file NetworkManager.h.
Referenced by autoDetectConnection(), createUDPConnection(), endConnection(), endUDPConnection(), shutdown(), startConnection(), startListener(), and stopListener().
| uint32 cmlabs::NetworkChannel::cid |
Channel id within the manager.
Definition at line 430 of file NetworkManager.h.
Referenced by cmlabs::NetworkManager::addTCPConnection(), cmlabs::NetworkManager::addTCPConnection(), cmlabs::NetworkManager::createListener(), cmlabs::NetworkManager::createTCPConnection(), cmlabs::NetworkManager::createTCPConnection(), cmlabs::NetworkManager::createTCPConnection(), cmlabs::NetworkManager::createUDPConnection(), cmlabs::NetworkManager::createWebsocketConnection(), cmlabs::NetworkManager::createWebsocketConnection(), enterNetworkEvent(), and startListener().
|
protected |
Worker threads by connection id (owned).
Definition at line 572 of file NetworkManager.h.
Referenced by autoDetectConnection(), createUDPConnection(), endConnection(), getConnectionType(), getInputSpeed(), getOutputSpeed(), getRemoteAddress(), isConnected(), sendHTTPReply(), sendHTTPRequest(), sendMessage(), sendReceiveHTTPRequest(), sendReceiveTelnetLine(), sendTelnetLine(), sendWebsocketData(), shutdown(), and startConnection().
|
protected |
Definition at line 576 of file NetworkManager.h.
Referenced by enterNetworkEvent(), shutdown(), and waitForNetworkEvent().
|
protected |
Definition at line 578 of file NetworkManager.h.
Referenced by enterNetworkEvent(), shutdown(), and waitForNetworkEvent().
|
protected |
Definition at line 577 of file NetworkManager.h.
Referenced by enterNetworkEvent(), and waitForNetworkEvent().
|
protected |
TCP listener threads by port (owned).
Definition at line 573 of file NetworkManager.h.
Referenced by shutdown(), startListener(), and stopListener().
|
protected |
Owning manager (not owned).
Definition at line 570 of file NetworkManager.h.
Referenced by applySSLClientPolicy(), autoDetectConnection(), endConnection(), NetworkChannel(), NetworkManager, startConnection(), startListener(), and ~NetworkChannel().
|
protected |
Definition at line 597 of file NetworkManager.h.
Referenced by enterHTTPReply(), shutdown(), and waitForHTTPReply().
|
protected |
Definition at line 599 of file NetworkManager.h.
Referenced by enterHTTPReply(), shutdown(), and waitForHTTPReply().
|
protected |
Definition at line 598 of file NetworkManager.h.
Referenced by enterHTTPReply(), and waitForHTTPReply().
|
protected |
Definition at line 594 of file NetworkManager.h.
Referenced by enterHTTPRequest(), shutdown(), and waitForHTTPRequest().
|
protected |
Definition at line 596 of file NetworkManager.h.
Referenced by enterHTTPRequest(), shutdown(), and waitForHTTPRequest().
|
protected |
Definition at line 595 of file NetworkManager.h.
Referenced by enterHTTPRequest(), and waitForHTTPRequest().
|
protected |
Definition at line 601 of file NetworkManager.h.
Referenced by enterMessage(), shutdown(), and waitForMessage().
|
protected |
Definition at line 600 of file NetworkManager.h.
Referenced by enterMessage(), shutdown(), and waitForMessage().
|
protected |
Definition at line 603 of file NetworkManager.h.
Referenced by enterMessage(), shutdown(), and waitForMessage().
|
protected |
Definition at line 602 of file NetworkManager.h.
Referenced by enterMessage(), and waitForMessage().
|
protected |
Definition at line 604 of file NetworkManager.h.
Referenced by enterTelnetLine(), shutdown(), and waitForTelnetLine().
|
protected |
Definition at line 606 of file NetworkManager.h.
Referenced by enterTelnetLine(), shutdown(), and waitForTelnetLine().
|
protected |
Definition at line 605 of file NetworkManager.h.
Referenced by enterTelnetLine(), and waitForTelnetLine().
|
protected |
Definition at line 607 of file NetworkManager.h.
Referenced by enterWebsocketData(), shutdown(), and waitForWebsocketData().
|
protected |
Definition at line 609 of file NetworkManager.h.
Referenced by enterWebsocketData(), shutdown(), and waitForWebsocketData().
|
protected |
Definition at line 608 of file NetworkManager.h.
Referenced by enterWebsocketData(), and waitForWebsocketData().
|
protected |
Async dispatch target (not owned; may be NULL).
Definition at line 571 of file NetworkManager.h.
Referenced by enterHTTPReply(), enterHTTPRequest(), enterMessage(), enterNetworkEvent(), enterTelnetLine(), enterWebsocketData(), NetworkChannel(), and setNewReceiver().
| int8 cmlabs::NetworkChannel::sslAllowSelfSigned |
Definition at line 499 of file NetworkManager.h.
Referenced by applySSLClientPolicy(), NetworkChannel(), and setSSLAllowSelfSigned().
| std::string cmlabs::NetworkChannel::sslCAFile |
Definition at line 503 of file NetworkManager.h.
Referenced by applySSLClientPolicy(), and setSSLCALocation().
| std::string cmlabs::NetworkChannel::sslCAPath |
Definition at line 504 of file NetworkManager.h.
Referenced by applySSLClientPolicy(), and setSSLCALocation().
| bool cmlabs::NetworkChannel::sslCASet |
Definition at line 505 of file NetworkManager.h.
Referenced by applySSLClientPolicy(), NetworkChannel(), and setSSLCALocation().
|
protected |
UDP listener threads by port (owned).
Definition at line 574 of file NetworkManager.h.
Referenced by createUDPConnection(), and endUDPConnection().