-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
问题描述
在 host/src/transport/usb.cpp 的 usb_receive_complete_callback() 函数中(约第 435-437 行),当设备断开连接或重新提交传输失败时,当前实现直接调用 std::terminate() 导致进程崩溃。
设备断开是正常的外设操作事件,不应导致整个 SDK 进程终止,这会严重影响 SDK 的使用体验。
当前实现
int ret = libusb_submit_transfer(transfer);
if (ret != 0) [[unlikely]] {
if (ret == LIBUSB_ERROR_NO_DEVICE)
logger_.error("Failed to re-submit receive transfer: Device disconnected. Terminating...");
else
logger_.error("Failed to re-submit receive transfer: {} ({}). Terminating...", ret, libusb_errname(ret));
destroy_libusb_transfer(transfer);
// TODO: Replace abrupt termination with a flag and exception-based error handling
std::terminate();
}期望的改进
参考同文件中其他地方已使用的错误处理模式(如 stop_handling_events_ 标志),应该:
- 设置错误标志
stop_handling_events_ = true - 记录适当的错误状态(例如设置
last_error_或usb_error_成员变量,包含描述性的错误代码/消息) - 确保函数干净地返回,让上层能够检测标志并处理设备断开/重提交失败事件
- 不要终止进程或吞掉错误——通过现有的事件循环/条件变量或围绕
stop_handling_events_的状态检查路径传播错误状态
相关链接
- PR: LibRMCS v3 is READY! #11
- 相关讨论: LibRMCS v3 is READY! #11 (comment)
- 请求人: @qzhhhi
优先级
当前实现可以接受,但应在后续版本中优化以提供更好的错误处理和用户体验。
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Todo