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
76 numPacketBytes += strlen(key);76 numPacketBytes += strlen(key);
77 getPacket[numPacketBytes++] = '\0';77 getPacket[numPacketBytes++] = '\0';
78 78
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
79 // send the get to the data server82 // send the get to the data server
80 NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes);83 NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes);
81}84}
82 85
86
87
83void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {88void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {
84 89 removeMatchedPacketFromMap(packetData, numPacketBytes);
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 }
101}90}
102 91
103void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) {92void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) {
@@ -128,7 +117,11 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 24 unmodified lines
128 }117 }
129 } else {118 } else {
130 // user string was UUID, find matching avatar and associate data119 // user string was UUID, find matching avatar and associate data
120
131 }121 }
122
123 // remove the matched packet from our map so it isn't re-sent to the data-server
124 removeMatchedPacketFromMap(packetData, numPacketBytes);
132}125}
133 126
134void DataServerClient::processMessageFromDataServer(unsigned char* packetData, int numPacketBytes) {127void DataServerClient::processMessageFromDataServer(unsigned char* packetData, int numPacketBytes) {
@@ -144,6 +137,25 @@ void DataServerClient::processMessageFromDataServer(unsigned char* packetData, i · 9 unmodified lines
144 }137 }
145}138}
146 139
140void 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
147void DataServerClient::resendUnmatchedPackets() {159void DataServerClient::resendUnmatchedPackets() {
148 for (std::map<unsigned char*, int>::iterator mapIterator = _unmatchedPackets.begin();160 for (std::map<unsigned char*, int>::iterator mapIterator = _unmatchedPackets.begin();
149 mapIterator != _unmatchedPackets.end();161 mapIterator != _unmatchedPackets.end();