mirror of
https://github.com/tmate-io/tmate.git
synced 2025-08-09 05:54:47 +02:00
Sync OpenBSD patchset 498:
Convert the window pane (pty master side) fd over to use a bufferevent. The evbuffer API is very similar to the existing tmux buffer API so this was remarkably painless. Not many possible ways to do it, I suppose.
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
/* $Id: server-window.c,v 1.8 2009-11-08 22:59:53 tcunha Exp $ */
|
||||
/* $Id: server-window.c,v 1.9 2009-11-08 23:02:56 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -30,35 +30,6 @@ int server_window_check_content(
|
||||
struct session *, struct window *, struct window_pane *);
|
||||
void server_window_check_alive(struct window *);
|
||||
|
||||
/* Register windows for poll. */
|
||||
void
|
||||
server_window_prepare(void)
|
||||
{
|
||||
struct window *w;
|
||||
struct window_pane *wp;
|
||||
u_int i;
|
||||
int events;
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
||||
if ((w = ARRAY_ITEM(&windows, i)) == NULL)
|
||||
continue;
|
||||
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
if (wp->fd == -1)
|
||||
continue;
|
||||
events = 0;
|
||||
if (!server_window_backoff(wp))
|
||||
events |= EV_READ;
|
||||
if (BUFFER_USED(wp->out) > 0)
|
||||
events |= EV_WRITE;
|
||||
event_del(&wp->event);
|
||||
event_set(&wp->event,
|
||||
wp->fd, events, server_window_callback, wp);
|
||||
event_add(&wp->event, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if this window should suspend reading. */
|
||||
int
|
||||
server_window_backoff(struct window_pane *wp)
|
||||
@ -84,24 +55,6 @@ server_window_backoff(struct window_pane *wp)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Process a single window pane event. */
|
||||
void
|
||||
server_window_callback(int fd, short events, void *data)
|
||||
{
|
||||
struct window_pane *wp = data;
|
||||
|
||||
if (wp->fd == -1)
|
||||
return;
|
||||
|
||||
if (fd == wp->fd) {
|
||||
if (buffer_poll(fd, events, wp->in, wp->out) != 0) {
|
||||
close(wp->fd);
|
||||
wp->fd = -1;
|
||||
} else
|
||||
window_pane_parse(wp);
|
||||
}
|
||||
}
|
||||
|
||||
/* Window functions that need to happen every loop. */
|
||||
void
|
||||
server_window_loop(void)
|
||||
@ -116,6 +69,13 @@ server_window_loop(void)
|
||||
if (w == NULL)
|
||||
continue;
|
||||
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
if (server_window_backoff(wp))
|
||||
bufferevent_disable(wp->event, EV_READ);
|
||||
else
|
||||
bufferevent_enable(wp->event, EV_READ);
|
||||
}
|
||||
|
||||
for (j = 0; j < ARRAY_LENGTH(&sessions); j++) {
|
||||
s = ARRAY_ITEM(&sessions, j);
|
||||
if (s == NULL || !session_has(s, w))
|
||||
|
Reference in New Issue
Block a user