mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
committed by
Mathew Sutcliffe
parent
63f625fe4e
commit
66cf96d47f
@@ -20,6 +20,7 @@
|
||||
#include "blackmisc/datacache.h"
|
||||
#include "blackmisc/dbusserver.h"
|
||||
#include "blackmisc/directoryutils.h"
|
||||
#include "blackmisc/eventloop.h"
|
||||
#include "blackmisc/filelogger.h"
|
||||
#include "blackmisc/logcategory.h"
|
||||
#include "blackmisc/logcategorylist.h"
|
||||
@@ -349,13 +350,10 @@ namespace BlackCore
|
||||
CStatusMessageList CApplication::waitForSetup()
|
||||
{
|
||||
if (!this->m_setupReader) { return CStatusMessage(this).error("No setup reader"); }
|
||||
if (!this->m_setupReader->isSetupAvailable())
|
||||
CEventLoop::processEventsUntil(this, &CApplication::setupHandlingCompleted, 5000, [this]
|
||||
{
|
||||
QEventLoop eventLoop;
|
||||
QTimer::singleShot(5000, &eventLoop, &QEventLoop::quit);
|
||||
connect(this, &CApplication::setupHandlingCompleted, &eventLoop, &QEventLoop::quit);
|
||||
eventLoop.exec();
|
||||
}
|
||||
return this->m_setupReader->isSetupAvailable();
|
||||
});
|
||||
|
||||
// setup handling completed with success or failure, or we run into time out
|
||||
if (this->m_setupReader->isSetupAvailable()) { return CStatusMessage(this).info("Setup available"); }
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/eventloop.h"
|
||||
#include "blackmisc/network/networkutils.h"
|
||||
#include "blackmisc/network/server.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
@@ -86,32 +87,20 @@ namespace BlackMisc
|
||||
|
||||
bool CNetworkUtils::canConnect(const QString &hostAddress, int port, QString &message, int timeoutMs)
|
||||
{
|
||||
// KB: I have had an issue with QTcpSocket. It was stuck in HostLookupState and did
|
||||
// only recover after a reboot for no obvious reason.
|
||||
// Currently trying the ping alternative
|
||||
bool ping = CNetworkUtils::canPing(hostAddress);
|
||||
if (ping) { return true; }
|
||||
|
||||
// http://qt-project.org/forums/viewthread/9346
|
||||
// socket.waitForConnected() unrelaiable under Windows, see Qt docu
|
||||
QTcpSocket socket;
|
||||
QTcpSocket::SocketState socketState;
|
||||
socket.connectToHost(hostAddress, static_cast<quint16>(port), QTcpSocket::ReadOnly);
|
||||
socketState = socket.state();
|
||||
bool connected = (socketState == QTcpSocket::ConnectedState);
|
||||
bool connected = CEventLoop::processEventsUntil(&socket, &QTcpSocket::connected, timeoutMs, [&]
|
||||
{
|
||||
socket.connectToHost(hostAddress, static_cast<quint16>(port));
|
||||
});
|
||||
|
||||
if (!connected)
|
||||
{
|
||||
QEventLoop eventLoop;
|
||||
QObject::connect(&socket, &QTcpSocket::connected, &eventLoop, &QEventLoop::quit);
|
||||
QTimer::singleShot(timeoutMs, &eventLoop, &QEventLoop::quit);
|
||||
eventLoop.exec();
|
||||
message = QObject::tr("Connection failed : %1", "BlackMisc").arg(socket.errorString());
|
||||
}
|
||||
else
|
||||
{
|
||||
message = QObject::tr("OK, connected", "BlackMisc");
|
||||
}
|
||||
socketState = socket.state();
|
||||
connected = (socketState == QTcpSocket::ConnectedState);
|
||||
message = connected ?
|
||||
QObject::tr("OK, connected", "BlackMisc") :
|
||||
QObject::tr("Connection failed : '%1'", "BlackMisc").arg(socket.errorString());
|
||||
socket.close();
|
||||
return connected;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user