mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 14:37:46 +02:00
add method to DataServerClient to resend unmatched packets
This commit is contained in:
parent
26d5e2cfec
commit
7964f360ab
2 changed files with 25 additions and 13 deletions
|
@ -17,7 +17,7 @@
|
||||||
#include "DataServerClient.h"
|
#include "DataServerClient.h"
|
||||||
|
|
||||||
QString DataServerClient::_clientUsername;
|
QString DataServerClient::_clientUsername;
|
||||||
std::vector<unsigned char*> DataServerClient::_unmatchedPackets;
|
std::map<unsigned char*, int> DataServerClient::_unmatchedPackets;
|
||||||
|
|
||||||
const char DATA_SERVER_HOSTNAME[] = "127.0.0.1";
|
const char DATA_SERVER_HOSTNAME[] = "127.0.0.1";
|
||||||
const unsigned short DATA_SERVER_PORT = 3282;
|
const unsigned short DATA_SERVER_PORT = 3282;
|
||||||
|
@ -46,7 +46,7 @@ void DataServerClient::putValueForKey(const char* key, const char* value) {
|
||||||
putPacket[numPacketBytes++] = '\0';
|
putPacket[numPacketBytes++] = '\0';
|
||||||
|
|
||||||
// add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed
|
// add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed
|
||||||
_unmatchedPackets.push_back(putPacket);
|
_unmatchedPackets.insert(std::pair<unsigned char*, int>(putPacket, numPacketBytes));
|
||||||
|
|
||||||
// send this put request to the data server
|
// send this put request to the data server
|
||||||
NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes);
|
NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes);
|
||||||
|
@ -82,20 +82,20 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use
|
||||||
|
|
||||||
void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {
|
void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {
|
||||||
|
|
||||||
for (std::vector<unsigned char*>::iterator unconfirmedPacket = _unmatchedPackets.begin();
|
for (std::map<unsigned char*, int>::iterator mapIterator = _unmatchedPackets.begin();
|
||||||
unconfirmedPacket != _unmatchedPackets.end();
|
mapIterator != _unmatchedPackets.end();
|
||||||
++unconfirmedPacket) {
|
++mapIterator) {
|
||||||
if (memcmp(*unconfirmedPacket + sizeof(PACKET_TYPE),
|
if (memcmp(mapIterator->first + sizeof(PACKET_TYPE),
|
||||||
packetData + sizeof(PACKET_TYPE),
|
packetData + sizeof(PACKET_TYPE),
|
||||||
numPacketBytes - sizeof(PACKET_TYPE)) == 0) {
|
numPacketBytes - sizeof(PACKET_TYPE)) == 0) {
|
||||||
// this is a match - remove the confirmed packet from the vector so it isn't sent back out
|
|
||||||
_unmatchedPackets.erase(unconfirmedPacket);
|
// this is a match - remove the confirmed packet from the vector and delete associated member
|
||||||
|
// so it isn't sent back out
|
||||||
|
delete[] mapIterator->first;
|
||||||
|
_unmatchedPackets.erase(mapIterator);
|
||||||
|
|
||||||
// we've matched the packet - bail out
|
// we've matched the packet - bail out
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
// no match, just push the iterator
|
|
||||||
unconfirmedPacket++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,3 +143,14 @@ void DataServerClient::processMessageFromDataServer(unsigned char* packetData, i
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataServerClient::resendUnmatchedPackets() {
|
||||||
|
for (std::map<unsigned char*, int>::iterator mapIterator = _unmatchedPackets.begin();
|
||||||
|
mapIterator != _unmatchedPackets.end();
|
||||||
|
++mapIterator) {
|
||||||
|
// send the unmatched packet to the data server
|
||||||
|
NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET,
|
||||||
|
mapIterator->first,
|
||||||
|
mapIterator->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#ifndef __hifi__DataServerClient__
|
#ifndef __hifi__DataServerClient__
|
||||||
#define __hifi__DataServerClient__
|
#define __hifi__DataServerClient__
|
||||||
|
|
||||||
#include <vector>
|
#include <map>
|
||||||
|
|
||||||
#include <QtCore/QUuid>
|
#include <QtCore/QUuid>
|
||||||
|
|
||||||
|
@ -22,12 +22,13 @@ public:
|
||||||
static void processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes);
|
static void processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes);
|
||||||
static void processSendFromDataServer(unsigned char* packetData, int numPacketBytes);
|
static void processSendFromDataServer(unsigned char* packetData, int numPacketBytes);
|
||||||
static void processMessageFromDataServer(unsigned char* packetData, int numPacketBytes);
|
static void processMessageFromDataServer(unsigned char* packetData, int numPacketBytes);
|
||||||
|
static void resendUnmatchedPackets();
|
||||||
|
|
||||||
static void setClientUsername(const QString& clientUsername) { _clientUsername = clientUsername; }
|
static void setClientUsername(const QString& clientUsername) { _clientUsername = clientUsername; }
|
||||||
static QString& setClientUsername() { return _clientUsername; }
|
static QString& setClientUsername() { return _clientUsername; }
|
||||||
private:
|
private:
|
||||||
static QString _clientUsername;
|
static QString _clientUsername;
|
||||||
static std::vector<unsigned char*> _unmatchedPackets;
|
static std::map<unsigned char*, int> _unmatchedPackets;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace DataServerKey {
|
namespace DataServerKey {
|
||||||
|
|
Loading…
Reference in a new issue