TDME2  1.9.200
UDPServerIOThread.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <queue>
5 #include <unordered_map>
6 
8 
9 #include <tdme/tdme.h>
15 
19 
20 using std::queue;
21 using std::unique_ptr;
22 using std::unordered_map;
23 
32 
33 /**
34  * UDP Network server IO thread
35  * @author Andreas Drewke
36  */
38  friend class UDPServer;
39  friend class UDPServerClient;
40 
41 private:
42  const static int MESSAGEACK_RESENDTIMES_TRIES = 7;
44  const static int MESSAGEQUEUE_SEND_BATCH_SIZE = 100;
45  const static uint64_t MESSAGEACK_KEEPTIME = 5000L;
46  struct Message {
47  string ip;
48  unsigned int port;
49  uint64_t time;
50  uint8_t messageType;
51  uint32_t clientId;
52  uint32_t messageId;
53  uint8_t retries;
54  char message[512];
55  uint16_t bytes;
56  };
57  typedef queue<Message*> MessageQueue;
58  typedef unordered_map<uint32_t, Message*> MessageMapAck;
60 
61 public:
62  // forbid class copy
64 
65  /**
66  * @brief public constructor should be called in TCPServer
67  * @param id id
68  * @param *server server
69  * @param maxCCU max ccu
70  * @param startUpBarrier start up barrier
71  */
72  UDPServerIOThread(const unsigned int id, UDPServer *server, const unsigned int maxCCU, Barrier* startUpBarrier);
73 
74  /**
75  * @brief Destructor
76  */
78 
79  /**
80  * @brief thread program
81  */
82  virtual void run();
83 
84  /**
85  * @brief pushes a message to be send, takes over ownership of frame
86  * @param client client
87  * @param messageType message type
88  * @param messageId message id
89  * @param packet packet to be send
90  * @param safe safe, requires ack and retransmission
91  * @param deletePacket delete packet
92  * @throws tdme::network::udpserver::NetworkServerException
93  */
94  void sendMessage(const UDPServerClient* client, const uint8_t messageType, const uint32_t messageId, const UDPPacket* packet, const bool safe, const bool deletePacket);
95 
96  /**
97  * @brief Processes an acknowlegdement reception
98  * @param client client
99  * @param messageId message id
100  * @throws tdme::network::udpserver::NetworkServerException
101  */
102  void processAckReceived(UDPServerClient* client, const uint32_t messageId);
103 
104  /**
105  * @brief Clean up timed out safe messages, reissue messages not beeing acknowlegded from client
106  */
107  void processAckMessages();
108 
109  //
110  unsigned int id;
112  unsigned int maxCCU;
114 
117 
120 
121  unique_ptr<UDPSocket> socket;
122 };
123 
Base class for network UDP server clients.
unordered_map< uint32_t, Message * > MessageMapAck
UDPServerIOThread(const unsigned int id, UDPServer *server, const unsigned int maxCCU, Barrier *startUpBarrier)
public constructor should be called in TCPServer
void processAckMessages()
Clean up timed out safe messages, reissue messages not beeing acknowlegded from client.
void processAckReceived(UDPServerClient *client, const uint32_t messageId)
Processes an acknowlegdement reception.
STATIC_DLL_IMPEXT static const uint64_t MESSAGEACK_RESENDTIMES[MESSAGEACK_RESENDTIMES_TRIES]
void sendMessage(const UDPServerClient *client, const uint8_t messageType, const uint32_t messageId, const UDPPacket *packet, const bool safe, const bool deletePacket)
pushes a message to be send, takes over ownership of frame
Base class for network UDP servers.
Definition: UDPServer.h:42
Interface to kernel event mechanismns.
Class representing a UDP socket.
Definition: UDPSocket.h:27
Barrier implementation.
Definition: Barrier.h:21
Mutex implementation.
Definition: Mutex.h:19
Base class for threads.
Definition: Thread.h:20
#define STATIC_DLL_IMPEXT
Definition: tdme.h:15
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6