allow a blocking lookup of IP address in HifiSockAddr

This commit is contained in:
Stephen Birarda 2014-11-03 15:13:41 -08:00
parent acef1b868c
commit 74753e5b8b
3 changed files with 12 additions and 10 deletions

View file

@ -96,17 +96,14 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) :
assignmentServerPort =
argumentVariantMap.value(CUSTOM_ASSIGNMENT_SERVER_PORT_OPTION).toString().toUInt();
}
HifiSockAddr assignmentServerSocket(DEFAULT_ASSIGNMENT_SERVER_HOSTNAME, assignmentServerPort);
// check for an overriden assignment server hostname
if (argumentVariantMap.contains(CUSTOM_ASSIGNMENT_SERVER_HOSTNAME_OPTION)) {
_assignmentServerHostname = argumentVariantMap.value(CUSTOM_ASSIGNMENT_SERVER_HOSTNAME_OPTION).toString();
// change the hostname for our assignment server
assignmentServerSocket = HifiSockAddr(_assignmentServerHostname, assignmentServerSocket.getPort());
_assignmentServerHostname = argumentVariantMap.value(CUSTOM_ASSIGNMENT_SERVER_HOSTNAME_OPTION).toString();
}
HifiSockAddr assignmentServerSocket(_assignmentServerHostname, assignmentServerPort, true);
nodeList->setAssignmentServerSocket(assignmentServerSocket);
qDebug() << "Assignment server socket is" << assignmentServerSocket;

View file

@ -36,15 +36,20 @@ HifiSockAddr::HifiSockAddr(const HifiSockAddr& otherSockAddr) {
_port = otherSockAddr._port;
}
HifiSockAddr::HifiSockAddr(const QString& hostname, quint16 hostOrderPort) :
HifiSockAddr::HifiSockAddr(const QString& hostname, quint16 hostOrderPort, bool shouldBlockForLookup) :
_address(hostname),
_port(hostOrderPort)
{
// if we parsed an IPv4 address out of the hostname, don't look it up
if (_address.protocol() != QAbstractSocket::IPv4Protocol) {
// sync lookup the IP by the hostname
int lookupID = QHostInfo::lookupHost(hostname, this, SLOT(handleLookupResult(QHostInfo)));
qDebug() << "Looking up IP address for hostname" << hostname << "- lookup ID is" << lookupID;
// lookup the IP by the hostname
if (shouldBlockForLookup) {
QHostInfo result = QHostInfo::fromName(hostname);
handleLookupResult(result);
} else {
int lookupID = QHostInfo::lookupHost(hostname, this, SLOT(handleLookupResult(QHostInfo)));
qDebug() << "Looking up IP address for hostname" << hostname << "- lookup ID is" << lookupID;
}
}
}

View file

@ -27,7 +27,7 @@ public:
HifiSockAddr();
HifiSockAddr(const QHostAddress& address, quint16 port);
HifiSockAddr(const HifiSockAddr& otherSockAddr);
HifiSockAddr(const QString& hostname, quint16 hostOrderPort);
HifiSockAddr(const QString& hostname, quint16 hostOrderPort, bool shouldBlockForLookup = false);
HifiSockAddr(const sockaddr* sockaddr);
bool isNull() const { return _address.isNull() && _port == 0; }