History

add method to DataServerClient to resend unmatched packets

Stephen Birarda committed 13 years ago

Commit 7964f361 parent 26d5e2c2 files · +25 −13Browse files

Showing the changes to interface/src/DataServerClient.cpp (1 of 2 files). Show all

Unified · Split

interface/src/DataServerClient.cpp+22−11
@@ -17,7 +17,7 @@ · 16 unmodified lines
1717 #include "DataServerClient.h"
1818
1919 QString DataServerClient::_clientUsername;
20−std::vector<unsigned char*> DataServerClient::_unmatchedPackets;
20+std::map<unsigned char*, int> DataServerClient::_unmatchedPackets;
2121
2222 const char DATA_SERVER_HOSTNAME[] = "127.0.0.1";
2323 const unsigned short DATA_SERVER_PORT = 3282;
@@ -46,7 +46,7 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { · 22 unmodified lines
4646 putPacket[numPacketBytes++] = '\0';
4747
4848 // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed
49− _unmatchedPackets.push_back(putPacket);
49+ _unmatchedPackets.insert(std::pair<unsigned char*, int>(putPacket, numPacketBytes));
5050
5151 // send this put request to the data server
5252 NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes);
@@ -82,20 +82,20 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use · 29 unmodified lines
8282
8383 void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {
8484
85− for (std::vector<unsigned char*>::iterator unconfirmedPacket = _unmatchedPackets.begin();
86− unconfirmedPacket != _unmatchedPackets.end();
87− ++unconfirmedPacket) {
88− if (memcmp(*unconfirmedPacket + sizeof(PACKET_TYPE),
85+ for (std::map<unsigned char*, int>::iterator mapIterator = _unmatchedPackets.begin();
86+ mapIterator != _unmatchedPackets.end();
87+ ++mapIterator) {
88+ if (memcmp(mapIterator->first + sizeof(PACKET_TYPE),
8989 packetData + sizeof(PACKET_TYPE),
9090 numPacketBytes - sizeof(PACKET_TYPE)) == 0) {
91− // this is a match - remove the confirmed packet from the vector so it isn't sent back out
92− _unmatchedPackets.erase(unconfirmedPacket);
91+
92+ // this is a match - remove the confirmed packet from the vector and delete associated member
93+ // so it isn't sent back out
94+ delete[] mapIterator->first;
95+ _unmatchedPackets.erase(mapIterator);
9396
9497 // we've matched the packet - bail out
9598 break;
96− } else {
97− // no match, just push the iterator
98− unconfirmedPacket++;
9999 }
100100 }
101101 }
@@ -143,3 +143,14 @@ void DataServerClient::processMessageFromDataServer(unsigned char* packetData, i · 41 unmodified lines
143143 break;
144144 }
145145 }
146+
147+void DataServerClient::resendUnmatchedPackets() {
148+ for (std::map<unsigned char*, int>::iterator mapIterator = _unmatchedPackets.begin();
149+ mapIterator != _unmatchedPackets.end();
150+ ++mapIterator) {
151+ // send the unmatched packet to the data server
152+ NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET,
153+ mapIterator->first,
154+ mapIterator->second);
155+ }
156+}