#include <TCPServer.h>
Public Member Functions | |
TCPServer (const String &listenerName, ServerConnection::Type connectionType, size_t threadLimit=16, LogEngine *logEngine=nullptr, const LogDetails &logDetails=LogDetails()) | |
~TCPServer () override | |
const Host & | host () const |
void | listen (uint16_t port) |
void | stop () override |
bool | active () const |
void | log (LogPriority priority, const String &message) const |
const LogDetails & | logDetails () const |
void | setSSLKeys (std::shared_ptr< SSLKeys > sslKeys) |
const SSLKeys & | getSSLKeys () const |
virtual void | onConnection (const ServerConnection::Function &function) |
Public Member Functions inherited from sptk::ThreadPool | |
ThreadPool (uint32_t threadLimit, std::chrono::milliseconds threadIdleSeconds, const String &threadName, LogEngine *logEngine) | |
virtual void | execute (const SRunable &task) |
void | threadEvent (Thread *thread, ThreadEvent::Type eventType, SRunable runable) override |
virtual void | stop () |
size_t | size () const |
Public Member Functions inherited from sptk::ThreadEvent | |
virtual void | threadEvent (Thread *thread, Type eventType, SRunable runable)=0 |
Thread event callback function. More... | |
virtual | ~ThreadEvent ()=default |
Destructor. | |
Protected Member Functions | |
void | host (const Host &host) |
virtual bool | allowConnection (sockaddr_in *connectionRequest) |
virtual SServerConnection | createConnection (SOCKET connectionSocket, const sockaddr_in *peer) |
void | threadEvent (Thread *thread, ThreadEvent::Type eventType, SRunable runable) override |
Friends | |
class | TCPServerListener |
class | ServerConnection |
Additional Inherited Members | |
Public Types inherited from sptk::ThreadEvent | |
enum class | Type : uint8_t { THREAD_STARTED , THREAD_FINISHED , RUNABLE_STARTED , RUNABLE_FINISHED , IDLE_TIMEOUT } |
Thread event type. More... | |
TCP server
For every incoming connection, creates connection thread.
sptk::TCPServer::TCPServer | ( | const String & | listenerName, |
ServerConnection::Type | connectionType, | ||
size_t | threadLimit = 16 , |
||
LogEngine * | logEngine = nullptr , |
||
const LogDetails & | logDetails = LogDetails() |
||
) |
Constructor
listenerName | Logical name of the listener |
threadLimit | Number of worker threads in thread pool |
logEngine | Optional log engine |
|
override |
Destructor
|
inline |
Returns server state
|
protectedvirtual |
Screens incoming connection request
Method is called right after connection request is accepted, and allows ignoring unwanted connections. By default simply returns true (allow).
connectionRequest | Incoming connection information |
|
protectedvirtual |
Creates connection thread derived from TCPServerConnection or SSLServerConnection
Application should override this method to create concrete connection object. Created connection object is maintained by CTCPServer.
connectionSocket | Already accepted incoming connection socket |
peer | Incoming connection information |
Reimplemented in sptk::WSListener.
const SSLKeys & sptk::TCPServer::getSSLKeys | ( | ) | const |
Get SSL keys for SSL connections (encrypted mode only)
Referenced by sptk::SSLServerConnection::SSLServerConnection().
const Host & sptk::TCPServer::host | ( | ) | const |
Get current host of the server
|
protected |
Modify server host. If listener is already active, don't modify exiting server host.
host | Server host |
void sptk::TCPServer::listen | ( | uint16_t | port | ) |
Starts listener
port | Listener port number |
|
inline |
Server operation log
priority | Log message priority |
message | Log message |
|
virtual |
Creates connection thread derived from TCPServerConnection or SSLServerConnection
Application should override this method to create concrete connection object. Created connection object is maintained by CTCPServer.
function | User-defined function that is called upon client connection to server |
void sptk::TCPServer::setSSLKeys | ( | std::shared_ptr< SSLKeys > | sslKeys | ) |
Set SSL keys for SSL connections (encrypted mode only)
sslKeys | SSL keys info |
|
overridevirtual |
Stops listener
Reimplemented from sptk::ThreadPool.
|
overrideprotectedvirtual |
Thread event callback function
Receives events that occur in the threads
thread | Thread where event occured |
eventType | Thread event type |
runable | Related runable (if any) |
Implements sptk::ThreadEvent.