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
17const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT);17const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT);
18 18
19void DataServerClient::putValueForKey(const char* key, const char* value) {19void 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];
21 21
22 // setup the header for this packet22 // setup the header for this packet
23 int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);23 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
37 numPacketBytes += strlen(value);37 numPacketBytes += strlen(value);
38 putPacket[numPacketBytes++] = '\0';38 putPacket[numPacketBytes++] = '\0';
39 39
40 // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed
41 _unconfirmedPackets.push_back(putPacket);
42
40 // send this put request to the data server43 // send this put request to the data server
41 NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes);44 NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes);
42}45}
@@ -63,6 +66,22 @@ void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) { · 20 unmodified lines
63 66
64void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {67void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {
65 68
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 }
66}85}
67 86
68void DataServerClient::processGetFromDataServer(unsigned char* packetData, int numPacketBytes) {87void DataServerClient::processGetFromDataServer(unsigned char* packetData, int numPacketBytes) {