TDME2 1.9.121
|
Base class for network UDP servers. More...
#include <tdme/network/udpserver/UDPServer.h>
Classes | |
struct | ClientId |
struct | UDPServer_Statistics |
Public Member Functions | |
UDPServer (const std::string &name, const std::string &host, const unsigned int port, const unsigned int maxCCU) | |
Public constructor. More... | |
virtual | ~UDPServer () |
destructor More... | |
virtual void | run () |
main event loop More... | |
const UDPServer_Statistics | getStatistics () |
![]() | |
Thread (const string &name, size_t stackSize=2 *1024 *1024) | |
Public constructor. More... | |
virtual | ~Thread () |
Public destructor. More... | |
void | join () |
Blocks caller thread until this thread has been terminated. More... | |
void | start () |
Starts this objects thread. More... | |
virtual void | run ()=0 |
Abstract run() method, should be implemented by subclassed class, will be called after spawn by start() More... | |
void | stop () |
Requests that this thread should be stopped. More... | |
bool | isStopRequested () |
Returns if stop has been requested. More... | |
![]() | |
Server (const std::string &name, const std::string &host, const unsigned int port, const unsigned int maxCCU) | |
void | setIOThreadCount (const unsigned int ioThreadCount) |
Sets up the numbers of threads to handle IO and framing. More... | |
void | setWorkerThreadCount (const unsigned int workerThreadCount) |
Sets up the number of workers that handle requests in thread pool. More... | |
void | setThreadPoolMaxElements (const unsigned int maxElements) |
Sets up max number of elements in worker thread pool queue. More... | |
virtual | ~Server () |
destructor More... | |
ClientKeySet | getClientKeySet () |
get a copy of current client keys More... | |
UDPServerClient * | getClientByKey (const std::string &clientKey) |
retrieve a client by key, the client reference is acquired, must be released after usage More... | |
ClientKeySet | getGroupKeySet () |
get a copy of current group keys More... | |
UDPServerGroup * | getGroupByKey (const std::string &groupKey) |
retrieve a group by key, the group reference is acquired, must be released after usage More... | |
Protected Types | |
enum | MessageType { MESSAGETYPE_CONNECT = 0 , MESSAGETYPE_MESSAGE = 1 , MESSAGETYPE_ACKNOWLEDGEMENT = 2 } |
![]() | |
typedef std::map< const std::string, UDPServerClient * > | ClientKeyMap |
typedef std::map< const std::string, UDPServerClient * > | GroupKeyMap |
typedef std::set< UDPServerClient * > | ClientSet |
Protected Member Functions | |
virtual UDPServerClient * | accept (const uint32_t clientId, const std::string &ip, const unsigned int port) |
method to implement for accepting clients More... | |
virtual void | identify (stringstream *frame, MessageType &messageType, uint32_t &connectionId, uint32_t &messageId, uint8_t &retries) |
Identifies a client message. More... | |
virtual void | validate (stringstream *frame) |
Validates a client message. More... | |
virtual void | writeHeader (stringstream *frame, MessageType messageType, const uint32_t clientId, const uint32_t messageId, const uint8_t retries) |
Writes a message header to message. More... | |
![]() | |
bool | setClientKey (UDPServerClient *client, const std::string &clientKey) |
sets a client identification key More... | |
void | closeClient (UDPServerClient *client) |
closes a client connection More... | |
bool | setGroupKey (UDPServerGroup *group, const std::string &groupKey) |
sets a group identification key More... | |
void | closeGroup (UDPServerGroup *group) |
closes a group connection More... | |
Static Protected Member Functions | |
static void | initializeHeader (stringstream *frame) |
Writes a empty header to message. More... | |
Private Types | |
typedef std::map< uint32_t, ClientId * > | ClientIdMap |
typedef std::map< string, UDPServerClient * > | ClientIpMap |
typedef std::set< UDPServerClient * > | ClientSet |
Private Member Functions | |
void | addClient (UDPServerClient *client) |
maps a new client to a given client id More... | |
void | removeClient (UDPServerClient *client) |
removes a client More... | |
UDPServerClient * | lookupClient (const uint32_t clientId) |
Look ups a client by client id. More... | |
UDPServerClient * | getClientByIp (const string &ip, const unsigned int port) |
Returns client by host name and port. More... | |
void | cleanUpClients () |
Clean up clients that have been idle for some time or are flagged to be shut down. More... | |
void | sendMessage (const UDPServerClient *client, stringstream *frame, const bool safe, const bool deleteFrame, const MessageType messageType, const uint32_t messageId=MESSAGE_ID_NONE) |
pushes a message to be send, takes over ownership of frame More... | |
void | processAckReceived (UDPServerClient *client, const uint32_t messageId) |
Processes an acknowlegdement reception. More... | |
const uint32_t | allocateClientId () |
Allocates a client id for a new client. More... | |
Private Attributes | |
ClientIdMap | clientIdMap |
ReadWriteLock | clientIdMapReadWriteLock |
ClientIpMap | clientIpMap |
ReadWriteLock | clientIpMapReadWriteLock |
unsigned int | ioThreadCurrent |
UDPServerIOThread ** | ioThreads |
ServerWorkerThreadPool * | workerThreadPool |
uint32_t | clientCount |
uint32_t | messageCount |
UDPServer_Statistics | statistics |
Static Private Attributes | |
static const uint64_t | CLIENT_CLEANUP_IDLETIME = 120000L |
static const uint32_t | MESSAGE_ID_NONE = 0 |
Friends | |
class | UDPServerClient |
class | UDPServerIOThread |
class | ServerGroup< UDPServer, UDPServerClient, UDPServerGroup > |
Additional Inherited Members | |
![]() | |
typedef std::set< std::string > | ClientKeySet |
typedef std::set< std::string > | GroupKeySet |
![]() | |
static int | getHardwareThreadCount () |
static void | sleep (const uint64_t milliseconds) |
sleeps current thread for given time in milliseconds More... | |
![]() | |
std::string | name |
std::string | host |
unsigned int | port |
unsigned int | maxCCU |
Barrier * | startUpBarrier |
ClientKeyMap | clientKeyMap |
ClientKeySet | clientKeySet |
ReadWriteLock | clientKeyListsReadWriteLock |
GroupKeyMap | groupKeyMap |
GroupKeySet | groupKeySet |
ReadWriteLock | groupKeyListsReadWriteLock |
unsigned int | ioThreadCount |
unsigned int | workerThreadPoolCount |
unsigned int | workerThreadPoolMaxElements |
Base class for network UDP servers.
Definition at line 39 of file UDPServer.h.
|
private |
Definition at line 133 of file UDPServer.h.
|
private |
Definition at line 134 of file UDPServer.h.
|
private |
Definition at line 135 of file UDPServer.h.
|
protected |
Enumerator | |
---|---|
MESSAGETYPE_CONNECT | |
MESSAGETYPE_MESSAGE | |
MESSAGETYPE_ACKNOWLEDGEMENT |
Definition at line 79 of file UDPServer.h.
UDPServer | ( | const std::string & | name, |
const std::string & | host, | ||
const unsigned int | port, | ||
const unsigned int | maxCCU | ||
) |
Public constructor.
name | server name |
host | host where to bind the server socket |
port | port to listen on |
maxCCU | max ccu |
Definition at line 39 of file UDPServer.cpp.
|
virtual |
destructor
Definition at line 52 of file UDPServer.cpp.
|
protectedvirtual |
method to implement for accepting clients
clientId | client id |
ip | ip |
port | port |
Definition at line 163 of file UDPServer.cpp.
|
private |
maps a new client to a given client id
client | client |
tdme::network::udpserver::NetworkServerException | if id is already in use |
Definition at line 280 of file UDPServer.cpp.
|
private |
Allocates a client id for a new client.
Definition at line 495 of file UDPServer.cpp.
|
private |
Clean up clients that have been idle for some time or are flagged to be shut down.
Definition at line 436 of file UDPServer.cpp.
|
private |
Returns client by host name and port.
ip | ip |
port | port |
Definition at line 423 of file UDPServer.cpp.
const UDPServer::UDPServer_Statistics getStatistics | ( | ) |
Definition at line 499 of file UDPServer.cpp.
|
protectedvirtual |
Identifies a client message.
frame | frame |
messageType | message type (see UDPServer::MessageType) |
connectionId | connection id |
messageId | message id |
retries | retries |
Definition at line 167 of file UDPServer.cpp.
|
staticprotected |
Writes a empty header to message.
frame | frame |
Definition at line 229 of file UDPServer.cpp.
|
private |
Look ups a client by client id.
clientId | client id |
tdme::network::udpserver::NetworkServerException | if client does not exist |
Definition at line 389 of file UDPServer.cpp.
|
private |
Processes an acknowlegdement reception.
client | client |
messageId | message id |
Definition at line 490 of file UDPServer.cpp.
|
private |
removes a client
client | client |
tdme::network::udpserver::NetworkServerException | if id is not in use |
Definition at line 341 of file UDPServer.cpp.
|
virtual |
|
private |
pushes a message to be send, takes over ownership of frame
client | client |
frame | frame to be send |
safe | safe, requires ack and retransmission |
deleteFrame | delete frame |
messageType | message type |
messageId | message id (only for MESSAGETYPE_MESSAGE) |
Definition at line 469 of file UDPServer.cpp.
|
protectedvirtual |
|
protectedvirtual |
Writes a message header to message.
frame | frame |
messageType | message type |
clientId | client id |
messageId | message id |
retries | retries |
Definition at line 241 of file UDPServer.cpp.
|
friend |
Definition at line 41 of file UDPServer.h.
|
friend |
Definition at line 40 of file UDPServer.h.
|
friend |
Definition at line 41 of file UDPServer.h.
|
staticprivate |
Definition at line 127 of file UDPServer.h.
|
private |
Definition at line 210 of file UDPServer.h.
|
private |
Definition at line 200 of file UDPServer.h.
|
private |
Definition at line 201 of file UDPServer.h.
|
private |
Definition at line 203 of file UDPServer.h.
|
private |
Definition at line 204 of file UDPServer.h.
|
private |
Definition at line 206 of file UDPServer.h.
|
private |
Definition at line 207 of file UDPServer.h.
|
staticprivate |
Definition at line 136 of file UDPServer.h.
|
private |
Definition at line 211 of file UDPServer.h.
|
private |
Definition at line 213 of file UDPServer.h.
|
private |
Definition at line 208 of file UDPServer.h.