-
Notifications
You must be signed in to change notification settings - Fork 49
chore: replace the connectivity check type #480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
TAG Bot New tag: 2.0.80 |
| @@ -0,0 +1,193 @@ | |||
| // SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
时间改下,其他文件的也改下
8dd918d to
aad8e38
Compare
| if (enableConnectivity) { | ||
| qCDebug(DSM) << "uses local connectivity checker"; | ||
| LocalConnectionvityChecker *localChecker = new LocalConnectionvityChecker(m_ipConflictHandler, this); | ||
| qDebug() << "uses local connectivity checker"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用qCDebug(DSM),日志都要分类
deepin pr auto review这份代码主要对网络连接检测功能进行了重构,将原来基于QProcess调用curl命令的方式改为了直接使用libcurl库,并优化了检测逻辑。以下是对代码的详细审查和改进建议: 1. 语法逻辑优点:
问题和建议:
2. 代码质量优点:
问题和建议:
3. 代码性能优点:
问题和建议:
4. 代码安全优点:
问题和建议:
5. 具体代码改进建议
HttpReply *HttpManager::get(const QString &url)
{
// 添加URL验证
if (!isValidUrl(url)) {
qCWarning(DSM) << "Invalid URL:" << url;
HttpReply *reply = new HttpReply(this);
reply->setErrorMessage("Invalid URL");
return reply;
}
// ... 现有代码 ...
// 设置合理的超时范围
long timeout = static_cast<long>(SettingConfig::instance()->httpRequestTimeout());
timeout = qBound(5L, timeout, 300L); // 限制在5-300秒之间
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
// ... 现有代码 ...
}
void StatusChecker::realStartCheck()
{
// ... 现有代码 ...
for (const QString &url : m_checkUrls) {
HttpManager http;
HttpReply *httpReply = http.get(url);
// 确保HttpReply对象被正确删除
QScopedPointer<HttpReply> replyGuard(httpReply);
// ... 现有代码 ...
}
// ... 现有代码 ...
}
// 在connectivitychecker.h中添加
namespace {
constexpr int DEBOUNCE_INTERVAL_MS = 1000; // 防抖动间隔
constexpr int ACTIVE_CHECK_INTERVAL_MS = 2000; // 活跃检测间隔
constexpr int MAX_ACTIVE_CHECK_COUNT = 8; // 最大活跃检测次数
}总结这次重构整体上提高了代码的质量和性能,将网络检测逻辑从基于QProcess的方式改为直接使用libcurl是一个很好的改进。主要需要关注的是线程安全、资源管理和错误处理等方面的问题。建议在后续版本中逐步完善这些方面,使代码更加健壮和安全。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ut003640 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
used libcurl to check the connectivity
Log:replace the connectivity check type
Influence: 任务栏图标显示的状态是否正常
PMS: BUG-331389