Showing the changes to interface/src/DataServerClient.cpp (1 of 2 files). Show all
Unified · Split
| @@ -17,7 +17,7 @@ · 16 unmodified lines | ||
| 17 | 17 | #include "DataServerClient.h" |
| 18 | 18 | |
| 19 | 19 | QString DataServerClient::_clientUsername; |
| 20 | −std::vector<unsigned char*> DataServerClient::_unmatchedPackets; | |
| 20 | +std::map<unsigned char*, int> DataServerClient::_unmatchedPackets; | |
| 21 | 21 | |
| 22 | 22 | const char DATA_SERVER_HOSTNAME[] = "127.0.0.1"; |
| 23 | 23 | const unsigned short DATA_SERVER_PORT = 3282; |
| @@ -46,7 +46,7 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { · 22 unmodified lines | ||
| 46 | 46 | putPacket[numPacketBytes++] = '\0'; |
| 47 | 47 | |
| 48 | 48 | // 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)); | |
| 50 | 50 | |
| 51 | 51 | // send this put request to the data server |
| 52 | 52 | 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 | ||
| 82 | 82 | |
| 83 | 83 | void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { |
| 84 | 84 | |
| 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), | |
| 89 | 89 | packetData + sizeof(PACKET_TYPE), |
| 90 | 90 | 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); | |
| 93 | 96 | |
| 94 | 97 | // we've matched the packet - bail out |
| 95 | 98 | break; |
| 96 | − } else { | |
| 97 | − // no match, just push the iterator | |
| 98 | − unconfirmedPacket++; | |
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | } |
| @@ -143,3 +143,14 @@ void DataServerClient::processMessageFromDataServer(unsigned char* packetData, i · 41 unmodified lines | ||
| 143 | 143 | break; |
| 144 | 144 | } |
| 145 | 145 | } |
| 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 | +} | |