Showing the changes to interface/src/DataServerClient.cpp (1 of 2 files). Show all
Unified · Split
| @@ -76,28 +76,17 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use · 75 unmodified lines | ||
| 76 | 76 | numPacketBytes += strlen(key); |
| 77 | 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 | 82 | // send the get to the data server |
| 80 | 83 | NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); |
| 81 | 84 | } |
| 82 | 85 | |
| 86 | + | |
| 87 | + | |
| 83 | 88 | 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); | |
| 101 | 90 | } |
| 102 | 91 | |
| 103 | 92 | void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) { |
| @@ -128,7 +117,11 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 24 unmodified lines | ||
| 128 | 117 | } |
| 129 | 118 | } else { |
| 130 | 119 | // 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 | |
| 134 | 127 | void 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 | |
| 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 | + | |
| 147 | 159 | void DataServerClient::resendUnmatchedPackets() { |
| 148 | 160 | for (std::map<unsigned char*, int>::iterator mapIterator = _unmatchedPackets.begin(); |
| 149 | 161 | mapIterator != _unmatchedPackets.end(); |