Showing the changes to interface/src/DataServerClient.cpp (1 of 3 files). Show all
Unified · Split
| @@ -17,7 +17,7 @@ const unsigned short DATA_SERVER_PORT = 3282; · 16 unmodified lines | |||
| 17 | const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT); | 17 | const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT); |
| 18 | 18 | ||
| 19 | void DataServerClient::putValueForKey(const char* key, const char* value) { | 19 | 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]; |
| 21 | 21 | ||
| 22 | // setup the header for this packet | 22 | // 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 server | 43 | // 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 | ||
| 64 | void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { | 67 | void 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 | ||
| 68 | void DataServerClient::processGetFromDataServer(unsigned char* packetData, int numPacketBytes) { | 87 | void DataServerClient::processGetFromDataServer(unsigned char* packetData, int numPacketBytes) { |