mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-03 14:18:45 +00:00
update:完善forward重连机制
This commit is contained in:
parent
09dfda9358
commit
4e0ae9d13b
1 changed files with 12 additions and 5 deletions
|
@ -10,6 +10,7 @@
|
||||||
#define DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar"
|
#define DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar"
|
||||||
#define DEVICE_NAME_FIELD_LENGTH 64
|
#define DEVICE_NAME_FIELD_LENGTH 64
|
||||||
#define SOCKET_NAME "qtscrcpy"
|
#define SOCKET_NAME "qtscrcpy"
|
||||||
|
#define MAX_CONNECT_COUNT 20
|
||||||
|
|
||||||
Server::Server(QObject *parent) : QObject(parent)
|
Server::Server(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
@ -200,6 +201,12 @@ QTcpSocket *Server::getControlSocket()
|
||||||
|
|
||||||
void Server::stop()
|
void Server::stop()
|
||||||
{
|
{
|
||||||
|
if (m_tunnelForward) {
|
||||||
|
stopConnectTimeoutTimer();
|
||||||
|
} else {
|
||||||
|
stopAcceptTimeoutTimer();
|
||||||
|
}
|
||||||
|
|
||||||
if (m_videoSocket) {
|
if (m_videoSocket) {
|
||||||
m_videoSocket->close();
|
m_videoSocket->close();
|
||||||
m_videoSocket->deleteLater();
|
m_videoSocket->deleteLater();
|
||||||
|
@ -327,7 +334,7 @@ void Server::onConnectTimer()
|
||||||
{
|
{
|
||||||
// device server need time to start
|
// device server need time to start
|
||||||
// 这里连接太早时间不够导致安卓监听socket还没有建立,readInfo会失败,所以采取定时重试策略
|
// 这里连接太早时间不够导致安卓监听socket还没有建立,readInfo会失败,所以采取定时重试策略
|
||||||
// 每隔100ms尝试一次,最多尝试100次
|
// 每隔100ms尝试一次,最多尝试MAX_CONNECT_COUNT次
|
||||||
QString deviceName;
|
QString deviceName;
|
||||||
QSize deviceSize;
|
QSize deviceSize;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
@ -338,7 +345,7 @@ void Server::onConnectTimer()
|
||||||
videoSocket->connectToHost(QHostAddress::LocalHost, m_params.localPort);
|
videoSocket->connectToHost(QHostAddress::LocalHost, m_params.localPort);
|
||||||
if (!videoSocket->waitForConnected(1000)) {
|
if (!videoSocket->waitForConnected(1000)) {
|
||||||
// 连接到adb很快的,这里失败不重试
|
// 连接到adb很快的,这里失败不重试
|
||||||
m_connectCount = 10;
|
m_connectCount = MAX_CONNECT_COUNT;
|
||||||
qWarning("video socket connect to server failed");
|
qWarning("video socket connect to server failed");
|
||||||
goto result;
|
goto result;
|
||||||
}
|
}
|
||||||
|
@ -346,7 +353,7 @@ void Server::onConnectTimer()
|
||||||
controlSocket->connectToHost(QHostAddress::LocalHost, m_params.localPort);
|
controlSocket->connectToHost(QHostAddress::LocalHost, m_params.localPort);
|
||||||
if (!controlSocket->waitForConnected(1000)) {
|
if (!controlSocket->waitForConnected(1000)) {
|
||||||
// 连接到adb很快的,这里失败不重试
|
// 连接到adb很快的,这里失败不重试
|
||||||
m_connectCount = 10;
|
m_connectCount = MAX_CONNECT_COUNT;
|
||||||
qWarning("control socket connect to server failed");
|
qWarning("control socket connect to server failed");
|
||||||
goto result;
|
goto result;
|
||||||
}
|
}
|
||||||
|
@ -366,7 +373,7 @@ void Server::onConnectTimer()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qWarning("connect to server failed");
|
qWarning("connect to server failed");
|
||||||
m_connectCount = 10;
|
m_connectCount = MAX_CONNECT_COUNT;
|
||||||
goto result;
|
goto result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,7 +396,7 @@ result:
|
||||||
controlSocket->deleteLater();
|
controlSocket->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (10 <= m_connectCount++) {
|
if (MAX_CONNECT_COUNT <= m_connectCount++) {
|
||||||
stopConnectTimeoutTimer();
|
stopConnectTimeoutTimer();
|
||||||
stop();
|
stop();
|
||||||
emit connectToResult(false);
|
emit connectToResult(false);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue