修复tunnelForward连接失败问题

This commit is contained in:
Barry 2018-11-22 22:31:25 +08:00
commit f9b31f420e

View file

@ -178,49 +178,53 @@ bool Server::connectTo()
return true; return true;
} }
QString deviceName; // device server need time to start
QSize deviceSize; QTimer::singleShot(600, this, [this](){
bool success = false; QString deviceName;
QSize deviceSize;
bool success = false;
m_deviceSocket = new DeviceSocket(); m_deviceSocket = new DeviceSocket();
// wait for devices server start // wait for devices server start
m_deviceSocket->connectToHost(QHostAddress::LocalHost, m_localPort); m_deviceSocket->connectToHost(QHostAddress::LocalHost, m_localPort);
if (!m_deviceSocket->waitForConnected(1000)) { if (!m_deviceSocket->waitForConnected(1000)) {
stop(); stop();
qWarning("connect to server failed"); qWarning("connect to server failed");
emit connectToResult(false, "", QSize()); emit connectToResult(false, "", QSize());
return false; return false;
} }
if (QTcpSocket::ConnectedState == m_deviceSocket->state()) { if (QTcpSocket::ConnectedState == m_deviceSocket->state()) {
// connect will success even if devices offline, recv data is real connect success // connect will success even if devices offline, recv data is real connect success
// because connect is to pc adb server // because connect is to pc adb server
m_deviceSocket->waitForReadyRead(1000); m_deviceSocket->waitForReadyRead(1000);
QByteArray data = m_deviceSocket->read(1); QByteArray data = m_deviceSocket->read(1);
if (!data.isEmpty() && readInfo(deviceName, deviceSize)) { if (!data.isEmpty() && readInfo(deviceName, deviceSize)) {
success = true; success = true;
} else {
qWarning("connect to server read device info failed");
success = false;
}
} else { } else {
qWarning("connect to server read device info failed"); qWarning("connect to server failed");
m_deviceSocket->deleteLater();
success = false; success = false;
} }
} else {
qWarning("connect to server failed");
m_deviceSocket->deleteLater();
success = false;
}
if (success) { if (success) {
// the server is started, we can clean up the jar from the temporary folder // the server is started, we can clean up the jar from the temporary folder
removeServer(); removeServer();
m_serverCopiedToDevice = false; m_serverCopiedToDevice = false;
// we don't need the adb tunnel anymore // we don't need the adb tunnel anymore
disableTunnelForward(); disableTunnelForward();
m_tunnelEnabled = false; m_tunnelEnabled = false;
} else { } else {
stop(); stop();
} }
emit connectToResult(success, deviceName, deviceSize); emit connectToResult(success, deviceName, deviceSize);
return success; });
return true;
} }
void Server::timerEvent(QTimerEvent *event) void Server::timerEvent(QTimerEvent *event)
@ -354,7 +358,13 @@ void Server::onWorkProcessResult(AdbProcess::ADB_EXEC_RESULT processResult)
case SSS_PUSH: case SSS_PUSH:
if (AdbProcess::AER_SUCCESS_EXEC == processResult) { if (AdbProcess::AER_SUCCESS_EXEC == processResult) {
m_serverCopiedToDevice = true; m_serverCopiedToDevice = true;
#if 1
m_serverStartStep = SSS_ENABLE_TUNNEL_REVERSE; m_serverStartStep = SSS_ENABLE_TUNNEL_REVERSE;
#else
// test tunnelForward
//m_tunnelForward = true;
//m_serverStartStep = SSS_ENABLE_TUNNEL_FORWARD;
#endif
startServerByStep(); startServerByStep();
} else if (AdbProcess::AER_SUCCESS_START != processResult){ } else if (AdbProcess::AER_SUCCESS_START != processResult){
qCritical("adb push"); qCritical("adb push");