]> git.sesse.net Git - bmusb/commitdiff
In v4l2proxy, check the return value of write().
authorSteinar H. Gunderson <steinar+nageru@gunderson.no>
Tue, 30 Apr 2024 19:47:11 +0000 (21:47 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 30 Apr 2024 19:48:09 +0000 (21:48 +0200)
This gives both support for partial writes, better error handling,
and resilience against EINTR.

v4l2proxy.cpp

index 4e0b36b3d1b40da41fbe07d10afc3abb67613ce1..7ead4aa1b60f352ca5070724aed68a9a0225f4e5 100644 (file)
@@ -12,6 +12,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <errno.h>
 #include <sys/ioctl.h>
 #include <linux/videodev2.h>
 #include <bmusb/bmusb.h>
@@ -84,7 +85,20 @@ void frame_callback(uint16_t timecode,
                }
 #endif
 
-               write(video_fd, origptr, video_frame.len);
+               size_t len = video_frame.len;
+               while (len > 0) {
+                       ssize_t ret = write(video_fd, origptr, len);
+                       if (ret == -1) {
+                               if (errno == EINTR) {
+                                       continue;
+                               } else {
+                                       perror("write");
+                                       break;  // Hope for better luck next frame.
+                               }
+                       }
+                       origptr += ret;
+                       len -= ret;
+               }
        }
 
        usb->get_video_frame_allocator()->release_frame(video_frame);