Abort connection if bad data received from drone
Currently we would crash because of qFatal(). The new behaviour is better. Error is reported in the logs window alongwith a suggestion on what to check.
This commit is contained in:
parent
1e1e0b0c48
commit
dccf2042f0
@ -241,7 +241,8 @@ _error_exit:
|
||||
|
||||
void PortGroup::on_rpcChannel_disconnected()
|
||||
{
|
||||
qDebug("disconnected\n");
|
||||
qDebug("disconnected %s:%u",
|
||||
qPrintable(rpcChannel->serverName()), rpcChannel->serverPort());
|
||||
logError(id(), "PortGroup disconnected");
|
||||
emit portListAboutToBeChanged(mPortGroupId);
|
||||
|
||||
@ -265,11 +266,26 @@ void PortGroup::on_rpcChannel_disconnected()
|
||||
|
||||
void PortGroup::on_rpcChannel_error(QAbstractSocket::SocketError socketError)
|
||||
{
|
||||
qDebug("%s: error %d", __FUNCTION__, socketError);
|
||||
qDebug("%s: error %d %s:%u", __FUNCTION__, socketError,
|
||||
qPrintable(rpcChannel->serverName()), rpcChannel->serverPort());
|
||||
emit portGroupDataChanged(mPortGroupId);
|
||||
|
||||
if (socketError == QAbstractSocket::RemoteHostClosedError)
|
||||
switch(socketError)
|
||||
{
|
||||
case QAbstractSocket::SslInvalidUserDataError: // actually abort()
|
||||
logWarn(id(), QString("Bad data received from portgroup, "
|
||||
"aborting connection; "
|
||||
"who is listening on %1:%2 "
|
||||
" - is it drone or some other process?")
|
||||
.arg(rpcChannel->serverName())
|
||||
.arg(rpcChannel->serverPort()));
|
||||
// fall-through
|
||||
case QAbstractSocket::RemoteHostClosedError:
|
||||
reconnect = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
qDebug("%s: state %d", __FUNCTION__, rpcChannel->state());
|
||||
if ((rpcChannel->state() == QAbstractSocket::UnconnectedState) && reconnect)
|
||||
|
@ -421,8 +421,13 @@ _top:
|
||||
}
|
||||
|
||||
default:
|
||||
qFatal("%s: unexpected type %d", __PRETTY_FUNCTION__, type);
|
||||
goto _error_exit;
|
||||
qWarning("%s: unexpected type %d", __PRETTY_FUNCTION__, type);
|
||||
qWarning("aborting %s:%u", qPrintable(mServerHost), mServerPort);
|
||||
// emit a error for user reporting; we are not a SSL socket,
|
||||
// so we overload a SSL error to indicate abort
|
||||
emit error(QAbstractSocket::SslInvalidUserDataError);
|
||||
mpSocket->abort();
|
||||
goto _exit2;
|
||||
|
||||
}
|
||||
|
||||
@ -467,6 +472,7 @@ _exit:
|
||||
}
|
||||
if (mpSocket->bytesAvailable())
|
||||
qDebug("%s (exit): bytesAvail = %lld", __FUNCTION__, mpSocket->bytesAvailable());
|
||||
_exit2:
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user