diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2010-08-11 07:34:43 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2010-08-11 07:34:43 +0000 |
commit | 8363e31953a346b3cd4141bf30a8d79d37ca2674 (patch) | |
tree | 1052ae596f467e6f915c555530ce6b64df31e621 /server-client.c | |
parent | 933dc48de356e387c0c027e654e1ae5f2f24c711 (diff) |
Change the way backoff works. Instead of stopping reading from the pty
when the client tty backs up too much, just stop updating the tty and
only update the internal screen. Then when the tty recovers, force a
redraw.
This prevents a dodgy client from causing other clients to go into
backoff while still allowing tmux to be responsive (locally) when seeing
lots of output.
Diffstat (limited to 'server-client.c')
-rw-r--r-- | server-client.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/server-client.c b/server-client.c index b8ccbeff..059a5c89 100644 --- a/server-client.c +++ b/server-client.c @@ -492,6 +492,50 @@ server_client_check_exit(struct client *c) c->flags &= ~CLIENT_EXIT; } +/* + * Check if the client should backoff. During backoff, data from external + * programs is not written to the terminal. When the existing data drains, the + * client is redrawn. + * + * There are two backoff phases - both the tty and client have backoff flags - + * the first to allow existing data to drain and the latter to ensure backoff + * is disabled until the redraw has finished and prevent the redraw triggering + * another backoff. + */ +void +server_client_check_backoff(struct client *c) +{ + struct tty *tty = &c->tty; + size_t used; + + used = EVBUFFER_LENGTH(tty->event->output); + + /* + * If in the second backoff phase (redrawing), don't check backoff + * until the redraw has completed (or enough of it to drop below the + * backoff threshold). + */ + if (c->flags & CLIENT_BACKOFF) { + if (used > BACKOFF_THRESHOLD) + return; + c->flags &= ~CLIENT_BACKOFF; + return; + } + + /* Once drained, allow data through again and schedule redraw. */ + if (tty->flags & TTY_BACKOFF) { + if (used != 0) + return; + tty->flags &= ~TTY_BACKOFF; + c->flags |= (CLIENT_BACKOFF|CLIENT_REDRAWWINDOW|CLIENT_STATUS); + return; + } + + /* If too much data, start backoff. */ + if (used > BACKOFF_THRESHOLD) + tty->flags |= TTY_BACKOFF; +} + /* Check for client redraws. */ void server_client_check_redraw(struct client *c) @@ -520,6 +564,10 @@ server_client_check_redraw(struct client *c) if (c->flags & CLIENT_REDRAW) { screen_redraw_screen(c, 0, 0); c->flags &= ~(CLIENT_STATUS|CLIENT_BORDERS); + } else if (c->flags & CLIENT_REDRAWWINDOW) { + TAILQ_FOREACH(wp, &c->session->curw->window->panes, entry) + screen_redraw_pane(c, wp); + c->flags &= ~CLIENT_REDRAWWINDOW; } else { TAILQ_FOREACH(wp, &c->session->curw->window->panes, entry) { if (wp->flags & PANE_REDRAW) |