This commit is contained in:
Philip Rosedale 2014-11-04 14:12:24 -08:00
commit a6c8fb7449
4 changed files with 39 additions and 14 deletions

View file

@ -1148,7 +1148,7 @@ void DomainServer::performICEUpdates() {
}
void DomainServer::sendHeartbeatToIceServer() {
const HifiSockAddr ICE_SERVER_SOCK_ADDR = HifiSockAddr("ice.highfidelity.io", ICE_SERVER_DEFAULT_PORT);
static HifiSockAddr ICE_SERVER_SOCK_ADDR = HifiSockAddr("ice.highfidelity.io", ICE_SERVER_DEFAULT_PORT);
LimitedNodeList::getInstance()->sendHeartbeatToIceServer(ICE_SERVER_SOCK_ADDR);
}

View file

@ -14,6 +14,7 @@
#include <QtCore/QJsonDocument>
#include "Assignment.h"
#include "HifiSockAddr.h"
#include "NodeList.h"
#include "PacketHeaders.h"
#include "UserActivityLogger.h"
@ -144,7 +145,10 @@ void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname,
hardReset();
_iceDomainID = id;
_iceServerSockAddr = HifiSockAddr(iceServerHostname, ICE_SERVER_DEFAULT_PORT);
HifiSockAddr* replaceableSockAddr = &_iceServerSockAddr;
replaceableSockAddr->~HifiSockAddr();
replaceableSockAddr = new (replaceableSockAddr) HifiSockAddr(iceServerHostname, ICE_SERVER_DEFAULT_PORT);
// refresh our ICE client UUID to something new
_iceClientID = QUuid::createUuid();

View file

@ -31,9 +31,17 @@ HifiSockAddr::HifiSockAddr(const QHostAddress& address, quint16 port) :
}
HifiSockAddr::HifiSockAddr(const HifiSockAddr& otherSockAddr) {
_address = otherSockAddr._address;
_port = otherSockAddr._port;
HifiSockAddr::HifiSockAddr(const HifiSockAddr& otherSockAddr) :
_address(otherSockAddr._address),
_port(otherSockAddr._port)
{
}
HifiSockAddr& HifiSockAddr::operator=(const HifiSockAddr& rhsSockAddr) {
HifiSockAddr temp(rhsSockAddr);
swap(temp);
return *this;
}
HifiSockAddr::HifiSockAddr(const QString& hostname, quint16 hostOrderPort, bool shouldBlockForLookup) :
@ -44,12 +52,12 @@ HifiSockAddr::HifiSockAddr(const QString& hostname, quint16 hostOrderPort, bool
if (_address.protocol() != QAbstractSocket::IPv4Protocol) {
// lookup the IP by the hostname
if (shouldBlockForLookup) {
qDebug() << "Asynchronously looking up IP address for hostname" << hostname;
qDebug() << "Synchronously looking up IP address for hostname" << hostname;
QHostInfo result = QHostInfo::fromName(hostname);
handleLookupResult(result);
} else {
int lookupID = QHostInfo::lookupHost(hostname, this, SLOT(handleLookupResult(QHostInfo)));
qDebug() << "Synchronously looking up IP address for hostname" << hostname << "- lookup ID is" << lookupID;
qDebug() << "Asynchronously looking up IP address for hostname" << hostname << "- lookup ID is" << lookupID;
}
}
}
@ -64,13 +72,6 @@ HifiSockAddr::HifiSockAddr(const sockaddr* sockaddr) {
}
}
HifiSockAddr& HifiSockAddr::operator=(const HifiSockAddr& rhsSockAddr) {
_address = rhsSockAddr._address;
_port = rhsSockAddr._port;
return *this;
}
void HifiSockAddr::swap(HifiSockAddr& otherSockAddr) {
using std::swap;

View file

@ -46,6 +46,26 @@ quint64 usecTimestampNow() {
TIME_REFERENCE = QDateTime::currentMSecsSinceEpoch() * 1000; // ms to usec
timestampTimer.start();
usecTimestampNowIsInitialized = true;
} else {
// We've seen the QElapsedTimer begin to introduce dramatic errors if it's been
// continuously running for a long time. So we will periodically reset it.
const quint64 SECS_TO_NSECS = 1000000000;
const quint64 RESET_AFTER_ELAPSED_SECS = 60 * 60; // 1 hour: 60 minutes * 60 seconds
const quint64 RESET_AFTER_ELAPSED_NSECS = RESET_AFTER_ELAPSED_SECS * SECS_TO_NSECS;
const quint64 nsecsElapsed = timestampTimer.nsecsElapsed();
if (nsecsElapsed > RESET_AFTER_ELAPSED_NSECS) {
quint64 msecsElapsed = timestampTimer.restart();
quint64 usecsElapsed = nsecsElapsed / 1000; // nsec to usec
TIME_REFERENCE += usecsElapsed;
const bool wantDebug = false;
if (wantDebug) {
qDebug() << "usecTimestampNow() - resetting QElapsedTimer. ";
qDebug() << " RESET_AFTER_ELAPSED_NSECS:" << RESET_AFTER_ELAPSED_NSECS;
qDebug() << " nsecsElapsed:" << nsecsElapsed;
qDebug() << " msecsElapsed:" << msecsElapsed;
qDebug() << " usecsElapsed:" << usecsElapsed;
}
}
}
// usec nsec to usec usec