Commit: aed2bfe73d3afe9a37f9a39fdfbcfd08e20e09a5
Parent: afeabe75acbd1a6d5284e085b051930d9fc129f5
Author: Randy Palamar
Date: Mon, 24 Jun 2024 19:29:56 -0600
read all available data from child not just 4095 bytes
Diffstat:
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/os_unix.c b/os_unix.c
@@ -156,9 +156,7 @@ os_fork_child(char *cmd)
{
i32 cfd;
- struct termios raw;
- cfmakeraw(&raw);
- pid_t pid = forkpty(&cfd, NULL, &raw, NULL);
+ pid_t pid = forkpty(&cfd, NULL, NULL, NULL);
switch (pid) {
case -1:
@@ -204,14 +202,19 @@ os_child_exited(os_child c)
static size
os_read_from_child(os_child c, RingBuf *rb)
{
- size r = read(c.fd, rb->buf + rb->widx, rb->cap);
+ /* TODO: check if we need to care about unprocessed bytes from last run */
+ size r = 0, total_bytes_read = 0, remaining = rb->cap;
+ do {
+ remaining -= r;
+ total_bytes_read += r;
+ r = read(c.fd, rb->buf + rb->widx + total_bytes_read, remaining);
+ } while (r != -1);
ASSERT(rb->widx < rb->cap);
ASSERT(r <= rb->cap);
- ASSERT(r != -1);
- rb->widx += r;
- rb->filled += r;
+ rb->widx += total_bytes_read;
+ rb->filled += total_bytes_read;
CLAMP(rb->filled, 0, rb->cap);
if (rb->widx >= rb->cap)
@@ -219,7 +222,7 @@ os_read_from_child(os_child c, RingBuf *rb)
ASSERT(rb->filled >= 0);
ASSERT(rb->widx >= 0 && rb->widx < rb->cap);
- return r;
+ return total_bytes_read;
}
static void
diff --git a/terminal.c b/terminal.c
@@ -145,7 +145,6 @@ parse_csi(s8 *r)
u32 cp = get_ascii(r);
csi.raw.len++;
if (BETWEEN(cp, '0', '9')) {
- /* 123 */
csi.argv[csi.argc] *= 10;
csi.argv[csi.argc] += cp - '0';
continue;
@@ -162,6 +161,7 @@ parse_csi(s8 *r)
}
}
/* TODO: error case: needs more chars! */
+ ASSERT(0);
return csi;
}