From f0764c24d28517f87910a791001ae6f8411e09a8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 7 Jul 2022 09:40:25 +0530 Subject: [PATCH] Retry read/write while there is space --- prewarm-launcher.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/prewarm-launcher.c b/prewarm-launcher.c index 188f7c36f..0670ca1fd 100644 --- a/prewarm-launcher.c +++ b/prewarm-launcher.c @@ -361,13 +361,15 @@ send_launch_msg(void) { static bool read_or_transfer(int src_fd, int dest_fd, transfer_buf *t) { (void)dest_fd; - if (t->sz >= IO_BUZ_SZ) return true; - ssize_t n = safe_read(src_fd, t->buf + t->sz, IO_BUZ_SZ - t->sz); - if (n < 0) { - if (errno == EAGAIN || errno == EWOULDBLOCK) return true; - return false; + while(t->sz < IO_BUZ_SZ) { + ssize_t n = safe_read(src_fd, t->buf + t->sz, IO_BUZ_SZ - t->sz); + if (n < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK) return true; + return false; + } + if (!n) break; + t->sz += n; } - t->sz += n; return true; } @@ -378,15 +380,16 @@ read_or_transfer_from_child_tty(void) { static bool write_from_to(transfer_buf *src, int dest_fd) { - if (!src->sz) return true; - ssize_t n = safe_write(dest_fd, src->buf, src->sz); - if (n < 0) { - if (errno == EAGAIN || errno == EWOULDBLOCK) return true; - return false; - } - if (n > 0) { - src->sz -= n; - memmove(src->buf, src->buf + n, src->sz); + while (src->sz) { + ssize_t n = safe_write(dest_fd, src->buf, src->sz); + if (n < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK) return true; + return false; + } + if (n > 0) { + src->sz -= n; + memmove(src->buf, src->buf + n, src->sz); + } else break; } return true; }