lib-ucode: retry partial writes
authorFelix Fietkau <nbd@nbd.name>
Mon, 4 Dec 2023 18:54:21 +0000 (19:54 +0100)
committerFelix Fietkau <nbd@nbd.name>
Mon, 4 Dec 2023 18:55:55 +0000 (19:55 +0100)
Signed-off-by: Felix Fietkau <nbd@nbd.name>
lib-ucode.c

index 844daf8d39b6cdfe561596f1b60d5a141dd4ec99..8e042e3f99f36b8b4f97b2eae0ae0a3a573259d1 100644 (file)
@@ -273,17 +273,33 @@ uc_udebug_pcap_init(struct uc_pcap *p, uc_value_t *args)
        pcap_init(&p->pcap, &meta);
 }
 
+static void
+write_retry(int fd, const void *data, size_t len)
+{
+       do {
+               ssize_t cur;
+
+               cur = write(fd, data, len);
+               if (cur < 0) {
+                       if (errno == EINTR)
+                               continue;
+
+                       return;
+               }
+
+               data += cur;
+               len -= cur;
+       } while (len > 0);
+}
+
 static void
 uc_udebug_pcap_write_block(struct uc_pcap *p)
 {
        size_t len;
        void *data;
-       int ret;
 
        data = pcap_block_get(&len);
-       do {
-               ret = write(p->fd, data, len);
-       } while (ret < 0 && errno == EINTR);
+       write_retry(p->fd, data, len);
 }
 
 static uc_value_t *