mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-12 04:27:51 -05:00
term: always read *all* we can from the client before updating state
But place an upper limit on the number of iterations we read, to prevent starvation caused by a bad behaving client to constantly writes data.
This commit is contained in:
parent
d7d2aae053
commit
9d52c422e1
1 changed files with 17 additions and 10 deletions
27
terminal.c
27
terminal.c
|
|
@ -147,19 +147,26 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data)
|
|||
return true;
|
||||
#endif
|
||||
|
||||
uint8_t buf[24 * 1024];
|
||||
ssize_t count = pollin ? read(term->ptmx, buf, sizeof(buf)) : 0;
|
||||
|
||||
if (count < 0) {
|
||||
LOG_ERRNO("failed to read from pseudo terminal");
|
||||
return false;
|
||||
}
|
||||
|
||||
vt_from_slave(term, buf, count);
|
||||
|
||||
/* Prevent blinking while typing */
|
||||
term_cursor_blink_restart(term);
|
||||
|
||||
uint8_t buf[24 * 1024];
|
||||
ssize_t count = sizeof(buf);
|
||||
|
||||
const size_t max_iterations = 1024;
|
||||
|
||||
for (size_t i = 0; i < max_iterations && pollin && count == sizeof(buf); i++) {
|
||||
assert(pollin);
|
||||
count = read(term->ptmx, buf, sizeof(buf));
|
||||
|
||||
if (count < 0) {
|
||||
LOG_ERRNO("failed to read from pseudo terminal");
|
||||
return false;
|
||||
}
|
||||
|
||||
vt_from_slave(term, buf, count);
|
||||
}
|
||||
|
||||
/*
|
||||
* We likely need to re-render. But, we don't want to
|
||||
* do it immediately. Often, a single client operation
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue