Fix bug can not reconnect wired network after plug in wired cable

This commit is contained in:
chenlelin 2021-05-13 20:22:21 +08:00
parent ff36e2a620
commit 9c9fcf917b
3 changed files with 51 additions and 15 deletions

View File

@ -1740,7 +1740,9 @@ void KylinDBus::slot_timeout()
//有线网的Ip属性变化时的响应函数 //有线网的Ip属性变化时的响应函数
void KylinDBus::onLanIpPropertiesChanged() void KylinDBus::onLanIpPropertiesChanged()
{ {
emit this->updateWiredList(0); if (!mw->is_stop_check_net_state) {
emit this->updateWiredList(0);
}
} }
//无线网的Ip属性变化时的响应函数 //无线网的Ip属性变化时的响应函数

View File

@ -571,9 +571,10 @@ void MainWindow::initTimer()
QObject::connect(wiredCableUpTimer, SIGNAL(timeout()), this, SLOT(onCarrierUpHandle())); QObject::connect(wiredCableUpTimer, SIGNAL(timeout()), this, SLOT(onCarrierUpHandle()));
//网线拔出时定时执行 //网线拔出时定时执行
wiredCableDownTimer = new QTimer(this); // wiredCableDownTimer = new QTimer(this);
wiredCableDownTimer->setTimerType(Qt::PreciseTimer); // wiredCableDownTimer->setTimerType(Qt::PreciseTimer);
QObject::connect(wiredCableDownTimer, SIGNAL(timeout()), this, SLOT(onCarrierDownHandle())); // QObject::connect(wiredCableDownTimer, SIGNAL(timeout()), this, SLOT(onCarrierDownHandle()));
connect(this, SIGNAL(carrierDownHandle()), this, SLOT(onCarrierDownHandle()));
//定时处理异常网络即当点击Lan列表按钮时若lstate=2但任然有有线网连接的情况 //定时处理异常网络即当点击Lan列表按钮时若lstate=2但任然有有线网连接的情况
deleteLanTimer = new QTimer(this); deleteLanTimer = new QTimer(this);
@ -969,19 +970,29 @@ void MainWindow::onPhysicalCarrierChanged(bool flag)
is_stop_check_net_state = 1; is_stop_check_net_state = 1;
qDebug()<<"插入了有线网的网线"; qDebug()<<"插入了有线网的网线";
syslog(LOG_DEBUG,"wired physical cable is already plug in"); syslog(LOG_DEBUG,"wired physical cable is already plug in");
wiredCableUpTimer->start(2000); wiredCableUpTimer->start(4000);
} else { } else {
qDebug()<<"拔出了有线网的网线"; qDebug()<<"拔出了有线网的网线";
syslog(LOG_DEBUG,"wired physical cable is already plug out"); syslog(LOG_DEBUG,"wired physical cable is already plug out");
activeLanDisconn(); QtConcurrent::run([=](){
BackThread *bt = new BackThread(); while (1) {
IFace *iface = bt->execGetIface(); //activeLanDisconn();
if (iface->lstate != 0) { BackThread *bt = new BackThread();
is_stop_check_net_state = 1; IFace *iface = bt->execGetIface();
wiredCableDownTimer->start(2000); if (iface->lstate != 0) {
} is_stop_check_net_state = 1;
delete iface; sleep(2);
bt->deleteLater(); //wiredCableDownTimer->start(2000);
emit carrierDownHandle();
delete iface;
bt->deleteLater();
break;
}
delete iface;
bt->deleteLater();
sleep(2);
}
});
} }
} }
@ -999,7 +1010,17 @@ void MainWindow::onCarrierUpHandle()
void MainWindow::onCarrierDownHandle() void MainWindow::onCarrierDownHandle()
{ {
wiredCableDownTimer->stop(); syslog(LOG_DEBUG, "Wired net is disconnected");
QString txt(tr("Wired net is disconnected"));
objKyDBus->showDesktopNotify(txt);
currSelNetName = "";
oldActLanName = "";
oldDbusActLanDNS = 0;
//emit this->waitLanStop();
//this->ksnm->execGetLanList();
//wiredCableDownTimer->stop();
this->stopLoading(); this->stopLoading();
onBtnNetListClicked(0); onBtnNetListClicked(0);
is_stop_check_net_state = 0; is_stop_check_net_state = 0;
@ -1255,6 +1276,7 @@ void MainWindow::onBtnWifiClicked(int flag)
void MainWindow::onBtnNetListClicked(int flag) void MainWindow::onBtnNetListClicked(int flag)
{ {
qDebug() << Q_FUNC_INFO <<" --------------> 0000004";
this->is_btnLanList_clicked = 1; this->is_btnLanList_clicked = 1;
this->is_btnWifiList_clicked = 0; this->is_btnWifiList_clicked = 0;
end_rcv_rates = 0; end_rcv_rates = 0;
@ -3468,6 +3490,7 @@ void MainWindow::timeIntervalToConnectWifi()
//处理外界对网络的连接与断开 //处理外界对网络的连接与断开
void MainWindow::onExternalConnectionChange(QString type, bool isConnUp) void MainWindow::onExternalConnectionChange(QString type, bool isConnUp)
{ {
qDebug() << Q_FUNC_INFO <<" --------------> 0000000-0";
isReconnectingWifi = false; isReconnectingWifi = false;
if ( (type == "802-11-wireless" || type == "wifi") && !isConnUp ){ if ( (type == "802-11-wireless" || type == "wifi") && !isConnUp ){
@ -3476,6 +3499,8 @@ void MainWindow::onExternalConnectionChange(QString type, bool isConnUp)
if (type == "802-11-wireless" || type == "wifi") { if (type == "802-11-wireless" || type == "wifi") {
addNumberForWifi += 1; addNumberForWifi += 1;
} }
qDebug() << Q_FUNC_INFO <<" --------------> 0000000-1";
if (addNumberForWifi == 2) { if (addNumberForWifi == 2) {
//断开一个wifi的时候如果存在回连可能接连发出两个信号 //断开一个wifi的时候如果存在回连可能接连发出两个信号
//当连续发出wifi断开与连接的信号时短时间内addNumberForWifi值为2 //当连续发出wifi断开与连接的信号时短时间内addNumberForWifi值为2
@ -3494,6 +3519,8 @@ void MainWindow::onExternalConnectionChange(QString type, bool isConnUp)
addNumberForWifi = 0; addNumberForWifi = 0;
return; return;
} }
qDebug() << Q_FUNC_INFO <<" --------------> 0000000-2 type = " << type;
if ( (type == "802-11-wireless" || type == "wifi") && isConnUp ){ if ( (type == "802-11-wireless" || type == "wifi") && isConnUp ){
addNumberForWifi = 0; addNumberForWifi = 0;
} }
@ -3505,6 +3532,8 @@ void MainWindow::onExternalConnectionChange(QString type, bool isConnUp)
return; return;
} }
qDebug() << Q_FUNC_INFO <<" --------------> 0000000-3";
if (isToSetLanValue) { if (isToSetLanValue) {
if (type == "802-3-ethernet" || type == "ethernet") { if (type == "802-3-ethernet" || type == "ethernet") {
isLanBeConnUp = true; isLanBeConnUp = true;
@ -3519,16 +3548,20 @@ void MainWindow::onExternalConnectionChange(QString type, bool isConnUp)
} }
} }
qDebug() << Q_FUNC_INFO <<" --------------> 0000000";
if (!is_connect_hide_wifi && !is_stop_check_net_state) { if (!is_connect_hide_wifi && !is_stop_check_net_state) {
qDebug() << Q_FUNC_INFO <<" --------------> 0000001";
is_stop_check_net_state = 1; is_stop_check_net_state = 1;
if (type == "802-3-ethernet" || type == "ethernet") { if (type == "802-3-ethernet" || type == "ethernet") {
qDebug() << Q_FUNC_INFO <<" --------------> 0000002";
if (is_connect_net_failed) { if (is_connect_net_failed) {
qDebug()<<"debug: connect wired network failed, no need to refresh wired interface"; qDebug()<<"debug: connect wired network failed, no need to refresh wired interface";
is_connect_net_failed = 0; is_connect_net_failed = 0;
is_stop_check_net_state = 0; is_stop_check_net_state = 0;
} else { } else {
isToSetLanValue = false; isToSetLanValue = false;
qDebug() << Q_FUNC_INFO <<" --------------> 0000003";
QTimer::singleShot(2*1000, this, SLOT(onExternalLanChange() )); QTimer::singleShot(2*1000, this, SLOT(onExternalLanChange() ));
} }
} }

View File

@ -408,6 +408,7 @@ private slots:
signals: signals:
void disConnSparedNet(QString type); void disConnSparedNet(QString type);
void refreshWifiListAfterScan(); void refreshWifiListAfterScan();
void carrierDownHandle();
void waitLanStop(); void waitLanStop();
void configurationChanged(); void configurationChanged();
void reConnectWifi(const QString& uuid); void reConnectWifi(const QString& uuid);