From 7f165ad0bd150ea34696067c8ebaa7af7afe2c27 Mon Sep 17 00:00:00 2001 From: litiangang4 Date: Wed, 13 Sep 2023 21:45:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=93=E5=BC=80=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E5=A4=B1=E8=B4=A5=E9=87=8D=E8=AF=95=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: litiangang4 --- utils/src/dinput_utils_tool.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index 70f5a25..f8f0d93 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -51,6 +51,8 @@ namespace { constexpr int32_t DOUBLE_TIMES = 2; constexpr int32_t INT32_STRING_LENGTH = 40; constexpr uint32_t ERROR_MSG_MAX_LEN = 256; + constexpr int32_t MAX_RETRY_COUNT = 5; + constexpr uint32_t SLEEP_TIME_US = 10 * 1000; } DevInfo GetLocalDeviceInfo() { @@ -337,8 +339,15 @@ int OpenInputDeviceFdByPath(const std::string &devicePath) return -1; } int fd = open(canonicalDevicePath, O_RDWR | O_CLOEXEC | O_NONBLOCK); - if (fd < 0) { - DHLOGE("could not open %s, %s\n", devicePath.c_str(), ConvertErrNo().c_str()); + int32_t count = 0; + while ((fd < 0) && (count < MAX_RETRY_COUNT)) { + ++count; + usleep(SLEEP_TIME_US); + fd = open(canonicalDevicePath, O_RDWR | O_CLOEXEC | O_NONBLOCK); + DHLOGE("could not open the path: %s, errno: %s; retry: %d", devicePath.c_str(), ConvertErrNo().c_str(), count); + } + if (count >= MAX_RETRY_COUNT) { + DHLOGE("could not open the path: %s, errno: %s.", devicePath.c_str(), ConvertErrNo().c_str()); CloseFd(fd); return -1; } -- Gitee