History

stubbing of mechanism to confirm packets sent to data server

Stephen Birarda committed 13 years ago

Commit 13232a41 parent 4cc9f293 files · +25 −1Browse files

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

Unified · Split

interface/src/DataServerClient.cpp+20−1
@@ -17,7 +17,7 @@ const unsigned short DATA_SERVER_PORT = 3282; · 16 unmodified lines
1717 const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT);
1818
1919 void DataServerClient::putValueForKey(const char* key, const char* value) {
20− unsigned char putPacket[MAX_PACKET_SIZE];
20+ unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE];
2121
2222 // setup the header for this packet
2323 int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);
@@ -37,6 +37,9 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { · 13 unmodified lines
3737 numPacketBytes += strlen(value);
3838 putPacket[numPacketBytes++] = '\0';
3939
40+ // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed
41+ _unconfirmedPackets.push_back(putPacket);
42+
4043 // send this put request to the data server
4144 NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes);
4245 }
@@ -63,6 +66,22 @@ void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) { · 20 unmodified lines
6366
6467 void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {
6568
69+ for (std::vector<unsigned char*>::iterator unconfirmedPacket = _unconfirmedPackets.begin();
70+ unconfirmedPacket != _unconfirmedPackets.end();
71+ ++unconfirmedPacket) {
72+ if (memcmp(*unconfirmedPacket + sizeof(PACKET_TYPE),
73+ packetData + sizeof(PACKET_TYPE),
74+ numPacketBytes - sizeof(PACKET_TYPE)) == 0) {
75+ // this is a match - remove the confirmed packet from the vector so it isn't sent back out
76+ _unconfirmedPackets.erase(unconfirmedPacket);
77+
78+ // we've matched the packet - bail out
79+ break;
80+ } else {
81+ // no match, just push the iterator
82+ unconfirmedPacket++;
83+ }
84+ }
6685 }
6786
6887 void DataServerClient::processGetFromDataServer(unsigned char* packetData, int numPacketBytes) {