[FSD] Fixed FSD socket error handling

This commit is contained in:
Klaus Basan
2019-10-24 03:37:20 +02:00
parent 5032e7fbd5
commit 5846576aae
2 changed files with 11 additions and 6 deletions

View File

@@ -91,7 +91,7 @@ namespace BlackCore
initializeMessageTypes(); initializeMessageTypes();
connect(&m_socket, &QTcpSocket::readyRead, this, &CFSDClient::readDataFromSocket); connect(&m_socket, &QTcpSocket::readyRead, this, &CFSDClient::readDataFromSocket);
connect(&m_socket, qOverload<QAbstractSocket::SocketError>(&QTcpSocket::error), this, &CFSDClient::printSocketError, Qt::QueuedConnection); connect(&m_socket, qOverload<QAbstractSocket::SocketError>(&QTcpSocket::error), this, &CFSDClient::printSocketError, Qt::QueuedConnection);
connect(&m_socket, qOverload<QAbstractSocket::SocketError>(&QTcpSocket::error), this, &CFSDClient::printSocketError, Qt::QueuedConnection); connect(&m_socket, qOverload<QAbstractSocket::SocketError>(&QTcpSocket::error), this, &CFSDClient::handleSocketError, Qt::QueuedConnection);
m_positionUpdateTimer.setObjectName(this->objectName().append(":m_positionUpdateTimer")); m_positionUpdateTimer.setObjectName(this->objectName().append(":m_positionUpdateTimer"));
connect(&m_positionUpdateTimer, &QTimer::timeout, this, &CFSDClient::sendPilotDataUpdate); connect(&m_positionUpdateTimer, &QTimer::timeout, this, &CFSDClient::sendPilotDataUpdate);
@@ -1369,14 +1369,12 @@ namespace BlackCore
void CFSDClient::printSocketError(QAbstractSocket::SocketError socketError) void CFSDClient::printSocketError(QAbstractSocket::SocketError socketError)
{ {
Q_UNUSED(socketError) CLogMessage(this).error(u"FSD socket error: %1") << socketErrorToQString(socketError);
const QString error = m_socket.errorString();
CLogMessage(this).error(u"FSD socket error: %1") << socketError;
} }
void CFSDClient::handleSocketError(QAbstractSocket::SocketError socketError) void CFSDClient::handleSocketError(QAbstractSocket::SocketError socketError)
{ {
const QString error = m_socket.errorString(); const QString error = socketErrorToQString(socketError);
switch (socketError) switch (socketError)
{ {
// all named here need a logoff // all named here need a logoff
@@ -1695,6 +1693,12 @@ namespace BlackCore
} }
} }
QString CFSDClient::socketErrorToQString(QAbstractSocket::SocketError error)
{
static const QMetaEnum metaEnum = QMetaEnum::fromType<QAbstractSocket::SocketError>();
return metaEnum.valueToKey(error);
}
void CFSDClient::parseMessage(const QString &line) void CFSDClient::parseMessage(const QString &line)
{ {
MessageType messageType = MessageType::Unknown; MessageType messageType = MessageType::Unknown;

View File

@@ -280,6 +280,7 @@ namespace BlackCore
void sendIncrementalAircraftConfig(); void sendIncrementalAircraftConfig();
void readDataFromSocket(); void readDataFromSocket();
QString socketErrorToQString(QAbstractSocket::SocketError error);
void parseMessage(const QString &line); void parseMessage(const QString &line);
void initializeMessageTypes(); void initializeMessageTypes();