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
17#include "DataServerClient.h"17#include "DataServerClient.h"
18 18
19QString DataServerClient::_clientUsername;19QString DataServerClient::_clientUsername;
20std::vector<unsigned char*> DataServerClient::_unmatchedPackets;20std::map<unsigned char*, int> DataServerClient::_unmatchedPackets;
21 21
22const char DATA_SERVER_HOSTNAME[] = "127.0.0.1";22const char DATA_SERVER_HOSTNAME[] = "127.0.0.1";
23const unsigned short DATA_SERVER_PORT = 3282;23const unsigned short DATA_SERVER_PORT = 3282;
@@ -46,7 +46,7 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { · 22 unmodified lines
46 putPacket[numPacketBytes++] = '\0';46 putPacket[numPacketBytes++] = '\0';
47 47
48 // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed48 // 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 // send this put request to the data server51 // send this put request to the data server
52 NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes);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
83void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {83void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {
84 84
85 for (std::vector<unsigned char*>::iterator unconfirmedPacket = _unmatchedPackets.begin();85 for (std::map<unsigned char*, int>::iterator mapIterator = _unmatchedPackets.begin();
86 unconfirmedPacket != _unmatchedPackets.end();86 mapIterator != _unmatchedPackets.end();
87 ++unconfirmedPacket) {87 ++mapIterator) {
88 if (memcmp(*unconfirmedPacket + sizeof(PACKET_TYPE),88 if (memcmp(mapIterator->first + sizeof(PACKET_TYPE),
89 packetData + sizeof(PACKET_TYPE),89 packetData + sizeof(PACKET_TYPE),
90 numPacketBytes - sizeof(PACKET_TYPE)) == 0) {90 numPacketBytes - sizeof(PACKET_TYPE)) == 0) {
91 // this is a match - remove the confirmed packet from the vector so it isn't sent back out91
92 _unmatchedPackets.erase(unconfirmedPacket);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 // we've matched the packet - bail out97 // we've matched the packet - bail out
95 break;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 break;143 break;
144 }144 }
145}145}
146
147void 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}