mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-23 13:55:36 +08:00
committed by
Mathew Sutcliffe
parent
63f625fe4e
commit
66cf96d47f
@@ -20,6 +20,7 @@
|
|||||||
#include "blackmisc/datacache.h"
|
#include "blackmisc/datacache.h"
|
||||||
#include "blackmisc/dbusserver.h"
|
#include "blackmisc/dbusserver.h"
|
||||||
#include "blackmisc/directoryutils.h"
|
#include "blackmisc/directoryutils.h"
|
||||||
|
#include "blackmisc/eventloop.h"
|
||||||
#include "blackmisc/filelogger.h"
|
#include "blackmisc/filelogger.h"
|
||||||
#include "blackmisc/logcategory.h"
|
#include "blackmisc/logcategory.h"
|
||||||
#include "blackmisc/logcategorylist.h"
|
#include "blackmisc/logcategorylist.h"
|
||||||
@@ -349,13 +350,10 @@ namespace BlackCore
|
|||||||
CStatusMessageList CApplication::waitForSetup()
|
CStatusMessageList CApplication::waitForSetup()
|
||||||
{
|
{
|
||||||
if (!this->m_setupReader) { return CStatusMessage(this).error("No setup reader"); }
|
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;
|
return this->m_setupReader->isSetupAvailable();
|
||||||
QTimer::singleShot(5000, &eventLoop, &QEventLoop::quit);
|
});
|
||||||
connect(this, &CApplication::setupHandlingCompleted, &eventLoop, &QEventLoop::quit);
|
|
||||||
eventLoop.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
// setup handling completed with success or failure, or we run into time out
|
// setup handling completed with success or failure, or we run into time out
|
||||||
if (this->m_setupReader->isSetupAvailable()) { return CStatusMessage(this).info("Setup available"); }
|
if (this->m_setupReader->isSetupAvailable()) { return CStatusMessage(this).info("Setup available"); }
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
* contained in the LICENSE file.
|
* contained in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "blackmisc/eventloop.h"
|
||||||
#include "blackmisc/network/networkutils.h"
|
#include "blackmisc/network/networkutils.h"
|
||||||
#include "blackmisc/network/server.h"
|
#include "blackmisc/network/server.h"
|
||||||
#include "blackconfig/buildconfig.h"
|
#include "blackconfig/buildconfig.h"
|
||||||
@@ -86,32 +87,20 @@ namespace BlackMisc
|
|||||||
|
|
||||||
bool CNetworkUtils::canConnect(const QString &hostAddress, int port, QString &message, int timeoutMs)
|
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 socket;
|
||||||
QTcpSocket::SocketState socketState;
|
bool connected = CEventLoop::processEventsUntil(&socket, &QTcpSocket::connected, timeoutMs, [&]
|
||||||
socket.connectToHost(hostAddress, static_cast<quint16>(port), QTcpSocket::ReadOnly);
|
{
|
||||||
socketState = socket.state();
|
socket.connectToHost(hostAddress, static_cast<quint16>(port));
|
||||||
bool connected = (socketState == QTcpSocket::ConnectedState);
|
});
|
||||||
|
|
||||||
if (!connected)
|
if (!connected)
|
||||||
{
|
{
|
||||||
QEventLoop eventLoop;
|
message = QObject::tr("Connection failed : %1", "BlackMisc").arg(socket.errorString());
|
||||||
QObject::connect(&socket, &QTcpSocket::connected, &eventLoop, &QEventLoop::quit);
|
}
|
||||||
QTimer::singleShot(timeoutMs, &eventLoop, &QEventLoop::quit);
|
else
|
||||||
eventLoop.exec();
|
{
|
||||||
|
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;
|
return connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user