usb: Read until buffer is fully filled 66/242866/1 accepted/tizen/unified/20200902.145546 submit/tizen/20200902.012141
authorDongwoo Lee <dwoo08.lee@samsung.com>
Tue, 1 Sep 2020 10:11:28 +0000 (19:11 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Tue, 1 Sep 2020 10:11:28 +0000 (19:11 +0900)
Since a single read may not fill the buffer entirely, this makes try
to fill the buffer fully with loop.

Change-Id: Ic73daf50b060f37c773774108952dbdf30de07e1
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
src/usb.c

index 9705b90..0c36fa0 100644 (file)
--- a/src/usb.c
+++ b/src/usb.c
@@ -198,7 +198,20 @@ static const struct {
 
 static ssize_t usb_rx_data(int fd, void *buf, ssize_t len)
 {
-       return read(fd, buf, len);
+       ssize_t r, count = 0;
+
+       do {
+               r = read(fd, buf + count, len - count);
+               if (r < 0) {
+                       if (errno == EINTR)
+                               continue;
+                       else
+                               return r;
+               }
+               count += r;
+       } while (count < len);
+
+       return count;
 }
 
 static ssize_t usb_tx_data(int fd, void *buf, ssize_t len)