|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
TCP server socket: binds a port and accepts inbound connections (plain or SSL). More...
#include <NetworkConnections.h>
Public Member Functions | |
| TCPListener () | |
| virtual | ~TCPListener () |
| bool | setSSLCertificate (const char *sslCertPath, const char *sslKeyPath) |
| Set the SSL certificate and private key used for inbound SSL connections. | |
| bool | init (uint16 port, uint8 encryption, NetworkConnectionReceiver *receiver=NULL, NetworkDataReceiver *dataReceiver=NULL) |
| Bind and start listening on a port. | |
| bool | disconnect (uint16 error=0) |
| Stop listening and close the socket. | |
| bool | isConnected () |
| uint64 | getLocalAddress () |
| NetworkConnection * | acceptConnection (uint32 timeout) |
| Synchronously wait for and accept one inbound connection. | |
| Public Member Functions inherited from cmlabs::Runnable | |
| Runnable () | |
| Initialise flags: not running, allowed to continue. | |
| virtual | ~Runnable () |
| Destructor requests a stop (with the default timeout) before destruction proceeds. | |
| virtual bool | stop (uint32 timeout=200) |
| Ask the worker loop to finish and wait for it to do so. | |
Friends | |
| THREAD_RET THREAD_FUNCTION_CALL | TCPListenerRun (THREAD_ARG arg) |
| Thread entry point for a TCPListener's internal accept loop. | |
Additional Inherited Members | |
| Protected Attributes inherited from cmlabs::Runnable | |
| uint32 | threadID |
| ThreadManager slot ID of the worker thread (0 until known). | |
| bool | shouldContinue |
| Loop-continuation flag; cleared by stop(). | |
| bool | isRunning |
| Set by the worker while its loop is active. | |
TCP server socket: binds a port and accepts inbound connections (plain or SSL).
A TCPListener owns one listening socket. After init(), connections can be accepted either synchronously via acceptConnection() or asynchronously by supplying a NetworkConnectionReceiver to init(), in which case an internal thread runs the accept loop. When encryption is SSLENC the accepted connections are SSLConnection objects using the certificate set with setSSLCertificate(); otherwise they are plain TCPConnection objects.
Definition at line 451 of file NetworkConnections.h.
| cmlabs::TCPListener::TCPListener | ( | ) |
Definition at line 67 of file NetworkConnections.cpp.
References CHECKNETWORKINIT, INVALID_SOCKET, NOENC, and cmlabs::Runnable::threadID.
Referenced by TCPListenerRun.
|
virtual |
Definition at line 79 of file NetworkConnections.cpp.
References disconnect(), INVALID_SOCKET, and cmlabs::Runnable::threadID.
| NetworkConnection * cmlabs::TCPListener::acceptConnection | ( | uint32 | timeout | ) |
Synchronously wait for and accept one inbound connection.
| timeout | Maximum wait in milliseconds. |
Definition at line 197 of file NetworkConnections.cpp.
References AESENC, closesocket, cmlabs::SSLConnection::connect(), cmlabs::TCPConnection::connect(), disconnect(), cmlabs::utils::GetLastOSErrorNumber(), cmlabs::GetTimeNow(), cmlabs::SSLConnection::init(), LOG_NETWORK, LogPrint, NETWORKERROR_ACCEPT, SD_BOTH, SOCKET, SOCKETTRYAGAIN, SOCKETWOULDBLOCK, SSLENC, and cmlabs::utils::WaitForSocketReadability().
Referenced by cmlabs::NetworkChannel::NetworkListenerRun(), and cmlabs::NetworkTest_TCPServer().
| bool cmlabs::TCPListener::disconnect | ( | uint16 | error = 0 | ) |
Stop listening and close the socket.
| error | Optional NETWORKERROR_* reason propagated to the receiver. |
Definition at line 101 of file NetworkConnections.cpp.
Referenced by acceptConnection(), and ~TCPListener().
| uint64 cmlabs::TCPListener::getLocalAddress | ( | ) |
Definition at line 187 of file NetworkConnections.cpp.
| bool cmlabs::TCPListener::init | ( | uint16 | port, |
| uint8 | encryption, | ||
| NetworkConnectionReceiver * | receiver = NULL, | ||
| NetworkDataReceiver * | dataReceiver = NULL ) |
Bind and start listening on a port.
| port | TCP port to bind on all local interfaces. |
| encryption | NOENC or SSLENC (requires a certificate to be set). |
| receiver | Optional; when non-NULL an internal thread accepts connections and pushes them to this receiver (async mode). |
| dataReceiver | Optional data receiver installed on each accepted connection. |
Definition at line 112 of file NetworkConnections.cpp.
References cmlabs::ThreadManager::CreateThread(), cmlabs::utils::GetLastOSErrorNumber(), INVALID_SOCKET, LOG_NETWORK, LogPrint, cmlabs::utils::SetSocketNonBlockingMode(), SOCKET_ERROR, TCPListenerRun, and cmlabs::Runnable::threadID.
Referenced by cmlabs::NetworkTest_TCPServer(), and cmlabs::NetworkChannel::startListener().
| bool cmlabs::TCPListener::isConnected | ( | ) |
Definition at line 108 of file NetworkConnections.cpp.
References INVALID_SOCKET.
| bool cmlabs::TCPListener::setSSLCertificate | ( | const char * | sslCertPath, |
| const char * | sslKeyPath ) |
Set the SSL certificate and private key used for inbound SSL connections.
| sslCertPath | Path to the PEM certificate file. |
| sslKeyPath | Path to the PEM private key file. |
Definition at line 191 of file NetworkConnections.cpp.
Referenced by cmlabs::NetworkChannel::startListener().
|
friend |
Thread entry point for a TCPListener's internal accept loop.
Definition at line 2824 of file NetworkConnections.cpp.
References TCPListener(), THREAD_ARG, THREAD_FUNCTION_CALL, THREAD_RET, and thread_ret_val.
Referenced by init().