History

re-send data-server GET requests if they are unmatched

Stephen Birarda committed 13 years ago

Commit 56b71eb1 parent 89261442 files · +30 −17Browse files

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

Unified · Split

interface/src/DataServerClient.cpp+29−17
@@ -76,28 +76,17 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use · 75 unmodified lines
7676 numPacketBytes += strlen(key);
7777 getPacket[numPacketBytes++] = '\0';
7878
79+ // add the getPacket to our vector of uncofirmed packets, will be deleted once we get a response from the nameserver
80+ _unmatchedPackets.insert(std::pair<unsigned char*, int>(getPacket, numPacketBytes));
81+
7982 // send the get to the data server
8083 NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes);
8184 }
8285
86+
87+
8388 void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {
84−
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),
89− packetData + sizeof(PACKET_TYPE),
90− numPacketBytes - sizeof(PACKET_TYPE)) == 0) {
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);
96−
97− // we've matched the packet - bail out
98− break;
99− }
100− }
89+ removeMatchedPacketFromMap(packetData, numPacketBytes);
10190 }
10291
10392 void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) {
@@ -128,7 +117,11 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 24 unmodified lines
128117 }
129118 } else {
130119 // user string was UUID, find matching avatar and associate data
120+
131121 }
122+
123+ // remove the matched packet from our map so it isn't re-sent to the data-server
124+ removeMatchedPacketFromMap(packetData, numPacketBytes);
132125 }
133126
134127 void DataServerClient::processMessageFromDataServer(unsigned char* packetData, int numPacketBytes) {
@@ -144,6 +137,25 @@ void DataServerClient::processMessageFromDataServer(unsigned char* packetData, i · 9 unmodified lines
144137 }
145138 }
146139
140+void DataServerClient::removeMatchedPacketFromMap(unsigned char* packetData, int numPacketBytes) {
141+ for (std::map<unsigned char*, int>::iterator mapIterator = _unmatchedPackets.begin();
142+ mapIterator != _unmatchedPackets.end();
143+ ++mapIterator) {
144+ if (memcmp(mapIterator->first + sizeof(PACKET_TYPE),
145+ packetData + sizeof(PACKET_TYPE),
146+ numPacketBytes - sizeof(PACKET_TYPE)) == 0) {
147+
148+ // this is a match - remove the confirmed packet from the vector and delete associated member
149+ // so it isn't sent back out
150+ delete[] mapIterator->first;
151+ _unmatchedPackets.erase(mapIterator);
152+
153+ // we've matched the packet - bail out
154+ break;
155+ }
156+ }
157+}
158+
147159 void DataServerClient::resendUnmatchedPackets() {
148160 for (std::map<unsigned char*, int>::iterator mapIterator = _unmatchedPackets.begin();
149161 mapIterator != _unmatchedPackets.end();