7 #ifndef __MessageReliableUDP_h__ 8 #define __MessageReliableUDP_h__ 29 #define RELIABLE_UDP_PACKET_SIZE (1024) 32 #define RELIABLE_UDP_MAX_PACKETS (128) 36 #define RELIABLE_UDP_MIN_RESPONSE_TIME (100) 39 #define RELIABLE_UDP_BURST_PACKET_LIMIT (10) 41 #define RELIABLE_UDP_RECEIVED_MAX_LIST (64) 50 uint16_t verificationPort;
60 uint8_t data[RELIABLE_UDP_PACKET_SIZE];
66 struct MultiPacketResponseMsg
69 std::bitset<RELIABLE_UDP_MAX_PACKETS> packetsReceived;
73 struct MultiPacketMsgInProgress
81 char ipAddress[INET_ADDRSTRLEN];
83 int64_t lastTransmitTime;
84 int64_t lastReceivedTime;
87 std::bitset<RELIABLE_UDP_MAX_PACKETS> packetsSent;
89 std::bitset<RELIABLE_UDP_MAX_PACKETS> packetsReceived;
91 bool doInitialTransmition;
94 bool partOfThisMessage(
const MultiPacketMsg &msg,
const char *msgIP)
const 96 return(messageID == msg.messageID &&
97 port == msg.verificationPort &&
98 strncmp(ipAddress, msgIP,
sizeof(ipAddress)) == 0);
101 bool receivedFullMessage()
const 103 return ((packetsReceived.count() * RELIABLE_UDP_PACKET_SIZE) >=
109 struct MultiPacketMsgReceived
112 char ipAddress[INET_ADDRSTRLEN];
113 uint16_t verificationPort;
115 bool operator==(
const MultiPacketMsgInProgress &msg)
const 117 return(messageID == msg.messageID &&
118 verificationPort == msg.port &&
119 strncmp(ipAddress, msg.ipAddress,
sizeof(ipAddress)) == 0);
135 virtual bool start(uint16_t receivePort)
override;
136 virtual uint16_t getReceivePort()
override;
137 virtual void shutdown()
override;
138 virtual bool recvReliableFrom(uint8_t **msg, uint32_t &msgSize,
139 char *fromIPaddress)
override;
140 virtual bool sendReliableTo(
const uint8_t *msg,
const uint32_t msgSize,
141 const char *ipAddress, uint16_t port)
override;
144 bool sendPacket(MultiPacketMsgInProgress &msg, uint32_t offset);
145 void checkVerifications();
146 void transmitThread();
147 void receiveThread();
149 bool sendResponseMsg(MultiPacketMsgInProgress &receivedMsg);
150 bool alreadyReceived(
const MultiPacketMsg &msg,
const char *msgIP);
151 bool alreadyReceived(
const MultiPacketMsgInProgress &testMsg);
155 Messagegram m_packetMsg;
156 Messagegram m_verificationMsg;
158 uint16_t m_verificationPort;
159 uint16_t m_receivePort;
160 int m_burstPacketLimit;
166 bool m_transmitThreadDone;
168 std::thread* m_transmitThread;
169 std::mutex m_transmitListLock;
170 I32 m_transmitListLockCount;
173 std::list<MultiPacketMsgInProgress> m_transmitList;
175 bool m_receiveThreadDone;
177 std::thread* m_receiveThread;
178 std::mutex m_receiveListLock;
179 I32 m_receiveListLockCount;
182 std::list<MultiPacketMsgInProgress> m_receiveList;
187 std::list<MultiPacketMsgReceived> m_fullyreceivedMsgList;
195 #endif // __MessageReliableUDP_h__ Message Sender/Receiver multi-packet reliable over UDP.
Definition: MessageReliableUDP.h:129
kernel
Definition: namespace.dox:3
Message Sender/Receiver multi-packet reliable over UDP.
Definition: MessageReliableUDPI.h:18
BWORD operator==(const DualString &s1, const DualString &s2)
Compare two DualString's.
Definition: DualString.h:208