From 43ab26f8315bbb7fbc26414d961df4c56d88c632 Mon Sep 17 00:00:00 2001 From: ishiguroJSK Date: Sun, 18 Aug 2019 17:21:05 +0900 Subject: [PATCH] handle return value of read() correctly --- src/main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1b3ecc5..3766cca 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -102,12 +102,15 @@ bool readCharFromSocket(const int& fdc, const int& length, char* reply){ int c = 0; while ( len < length ) { c = read(fdc, reply+len, length-len); - if (c >= 0) { + if (c > 0) { len += c; - } else { + } else if (c == 0) { ROS_DEBUG("=== need to read more data ... n = %d (%d) ===", c, len); - continue; + usleep(100); // polling @ 0.1 ms + } else { + ROS_WARN("read() error detected"); } + //ROS_INFO("c=%d, len=%d, length=%d", c, len, length); } // This could actually check if data was received and may return on timeout with false return true;