Merge branch 'master' of github.com:tmux/tmux

This commit is contained in:
Nicholas Marriott 2016-09-16 18:09:51 +01:00
commit cbde98f67b
2 changed files with 52 additions and 17 deletions

17
tmux.h
View File

@ -61,8 +61,18 @@ struct tmuxproc;
/* Automatic name refresh interval, in microseconds. Must be < 1 second. */
#define NAME_INTERVAL 500000
/* The maximum amount of data to hold from a pty (the event high watermark). */
#define READ_SIZE 4096
/*
* Event watermarks. We start with FAST then if we hit full size for HITS reads
* in succession switch to SLOW, and return when we hit EMPTY the same number
* of times.
*/
#define READ_FAST_SIZE 4096
#define READ_SLOW_SIZE 128
#define READ_FULL_SIZE (4096 - 16)
#define READ_EMPTY_SIZE 16
#define READ_CHANGE_HITS 3
/* Attribute to make gcc check printf-like arguments. */
#define printflike(a, b) __attribute__ ((format (printf, a, b)))
@ -886,6 +896,9 @@ struct window_pane {
int fd;
struct bufferevent *event;
u_int wmark_size;
u_int wmark_hits;
struct input_ctx *ictx;
struct grid_cell colgc;

View File

@ -56,15 +56,17 @@ struct windows windows;
/* Global panes tree. */
struct window_pane_tree all_window_panes;
u_int next_window_pane_id;
u_int next_window_id;
u_int next_active_point;
static u_int next_window_pane_id;
static u_int next_window_id;
static u_int next_active_point;
void window_pane_timer_callback(int, short, void *);
void window_pane_read_callback(struct bufferevent *, void *);
void window_pane_error_callback(struct bufferevent *, short, void *);
static void window_pane_set_watermark(struct window_pane *, size_t);
struct window_pane *window_pane_choose_best(struct window_pane **, u_int);
static void window_pane_read_callback(struct bufferevent *, void *);
static void window_pane_error_callback(struct bufferevent *, short, void *);
static struct window_pane *window_pane_choose_best(struct window_pane **,
u_int);
RB_GENERATE(windows, window, entry, window_cmp);
@ -812,6 +814,14 @@ window_pane_destroy(struct window_pane *wp)
free(wp);
}
static void
window_pane_set_watermark(struct window_pane *wp, size_t size)
{
wp->wmark_hits = 0;
wp->wmark_size = size;
bufferevent_setwatermark(wp->event, EV_READ, 0, size);
}
int
window_pane_spawn(struct window_pane *wp, int argc, char **argv,
const char *path, const char *shell, const char *cwd, struct environ *env,
@ -930,25 +940,37 @@ window_pane_spawn(struct window_pane *wp, int argc, char **argv,
wp->event = bufferevent_new(wp->fd, window_pane_read_callback, NULL,
window_pane_error_callback, wp);
bufferevent_setwatermark(wp->event, EV_READ, 0, READ_SIZE);
window_pane_set_watermark(wp, READ_FAST_SIZE);
bufferevent_enable(wp->event, EV_READ|EV_WRITE);
free(cmd);
return (0);
}
void
static void
window_pane_read_callback(__unused struct bufferevent *bufev, void *data)
{
struct window_pane *wp = data;
struct evbuffer *evb = wp->event->input;
size_t size = EVBUFFER_LENGTH(evb);
char *new_data;
size_t new_size;
log_debug("%%%u has %zu bytes (of %zu)", wp->id, EVBUFFER_LENGTH(evb),
(size_t)READ_SIZE);
if (wp->wmark_size == READ_FAST_SIZE) {
if (size > READ_FULL_SIZE)
wp->wmark_hits++;
if (wp->wmark_hits == READ_CHANGE_HITS)
window_pane_set_watermark(wp, READ_SLOW_SIZE);
} else if (wp->wmark_size == READ_SLOW_SIZE) {
if (size < READ_EMPTY_SIZE)
wp->wmark_hits++;
if (wp->wmark_hits == READ_CHANGE_HITS)
window_pane_set_watermark(wp, READ_FAST_SIZE);
}
log_debug("%%%u has %zu bytes (of %u, %u hits)", wp->id, size,
wp->wmark_size, wp->wmark_hits);
new_size = EVBUFFER_LENGTH(evb) - wp->pipe_off;
new_size = size - wp->pipe_off;
if (wp->pipe_fd != -1 && new_size > 0) {
new_data = EVBUFFER_DATA(evb) + wp->pipe_off;
bufferevent_write(wp->pipe_event, new_data, new_size);
@ -956,10 +978,10 @@ window_pane_read_callback(__unused struct bufferevent *bufev, void *data)
input_parse(wp);
wp->pipe_off = EVBUFFER_LENGTH(evb);
wp->pipe_off = size;
}
void
static void
window_pane_error_callback(__unused struct bufferevent *bufev,
__unused short what, void *data)
{
@ -1197,7 +1219,7 @@ window_pane_search(struct window_pane *wp, const char *searchstr,
}
/* Get MRU pane from a list. */
struct window_pane *
static struct window_pane *
window_pane_choose_best(struct window_pane **list, u_int size)
{
struct window_pane *next, *best;