From 1deaab39a80036118924ab4e446d4aa10f03ade9 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Tue, 30 Apr 2024 21:47:11 +0200 Subject: [PATCH] In v4l2proxy, check the return value of write(). This gives both support for partial writes, better error handling, and resilience against EINTR. --- v4l2proxy.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/v4l2proxy.cpp b/v4l2proxy.cpp index 4e0b36b..7ead4aa 100644 --- a/v4l2proxy.cpp +++ b/v4l2proxy.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -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); -- 2.39.5